function write_rbf(x_train,lambda,c,choice,filename) % This function creates an analytic RBF equation for a given set of % training points and RBF parameters. This does not build the metamodel, % RBF parameters from a pre-built model are input. These paramters can be % taken from get_ypred_rbf.m or by solving the RBF problem. % This function is set up to use MATLAB syntax for the output equation % ---Variable Descriptions--- % x_train = normalized design(training points): in an % [num_of_points by num_of_variables] matrix % lambda = array of RBF interpolation coefficients % c = user chosen RBF constant % choice = user chosen RBF radial basis function choice % --Currently Supported Basis Functions-- % choice = 1 -> Thin Plate; phi = r^2*ln(c*r) % choice = 2 -> Gaussian; phi = exp(-c*r^2) % choice = 3 -> Multiguadric; phi = sqrt(r^2+c^2) % choice = 4 -> Inverse Multiquadric; phi = 1/sqrt(r^2+c^2) % filename = string containing the filname to save the equation as, % must be "filename.txt" % number of design variables and number of training points. ndv = size(x_train,2); ntrn = size(x_train,1); % open output file with specified filename fout = fopen(filename,'w'); for k = 1:ntrn % define first characters of the line if k == 1 op = 'y_rbf='; else op = '+'; end % create appropriate lambda string lam = ['(' num2str(lambda(k,:)) ')']; % define Euclidean norm distance rsqrd and r rsqrd = []; r = []; for kk = 1:ndv if kk == 1 rsqrd = [rsqrd '(x' num2str(kk) '-' num2str(x_train(k,kk)) ').^2']; else rsqrd = [rsqrd '+(x' num2str(kk) '-' num2str(x_train(k,kk)) ').^2']; end end % write the equation based on which basis function was chosen if choice == 1 phi = ['(' rsqrd ')' '*log(' num2str(c) '*(sqrt(' rsqrd ')))...']; % "log" in MATLAB is ln not log10 print = [op lam '*' phi]; fprintf(fout,'%s\n',print); elseif choice == 2 phi = ['exp(-' num2str(c) '*(' rsqrd '))...']; print = [op lam '*' phi]; fprintf(fout,'%s\n',print); elseif choice == 3 phi = ['sqrt(' rsqrd '+(' num2str(c) ').^2)...']; print = [op lam '*' phi]; fprintf(fout,'%s\n',print); elseif choice == 4 phi = ['1/(sqrt(' rsqrd '+(' num2str(c) ').^2)...']; print = [op lam '*' phi]; fprintf(fout,'%s\n',print); end end fclose(fout);