Using results from genetic algorithm as initial values in least square non-linear fitting

4 views (last 30 days)
I have tried to take the initial values from genetic algorithm and use them in the least square nonlinear fit but every time I try to run the script,an error message appears.I have attached the data file.There are 4 variables Nu=f(Re,Theta,Beta).
clc
clear all
% Create an anonymous function that describes the expected relationship
% between X and Y
f=@(c,x) c(1).*(x(:,1).^c(2)).*exp((x(:,3)*c(4))+(x(:,2)*c(3)));
% data set
% Specify x variables from data file,Re,Theta and Beta columns.
x=xlsread('all data for fitting');
% Specify y variable from data file ,(Nu)column.
y=x(:,4);
% objective function
ff=@(c)(f(c,x)-y)./y;
% maximum of objective function
ffmax=@(c)norm(ff(c));
% Identifying population size and number of parameters for genetic
% algorithm
PopSz = 500;
Parms = 4;
% Modifying the options of genetic algotithm optimization function
options = optimoptions('ga', 'PopulationSize',PopSz, 'InitialPopulationMatrix',randi(1E+4,PopSz,Parms)*1E-4, 'MaxGenerations',2E3, 'PlotFcn',@gaplotbestf, 'PlotInterval',1);
% Genetic algorithm application
[theta,fval,exitflag,output] = ga(ffmax, Parms, [],[],[],[],-Inf(Parms,1),Inf(Parms,1),[],[],options);
% Specify a vector of starting conditions for the solvers(Least squre
% nnonlinear fit)
c0=[theta(1) ;theta(2);theta(3); theta(4)];
% Perform a nonlinear regression
c=lsqnonlin(ff,c0);
y1=f(c,x);
diff_Nu=y-y1;
Abs_diff_Nu=abs(diff_Nu);
perc_error=(Abs_diff_Nu./y);
x_line45=0:max(y);y_line45=0:max(y);
[max_error,I_max]=max(perc_error);
[min_error,I_min]=min(perc_error);
x_line_high=0:max(y); y_line_high=(max_error+1)*(0:max(y));
x_line_low=0:max(y); y_line_low=(1-max_error)*(0:max(y));
figure
plot(x_line45,y_line45,'k')
hold on
scatter(y,y1)
hold on
plot(x_line_high,y_line_high,'r')
hold on
plot(x_line_low,y_line_low,'r')
N=[y,y1];
header=['Nuact','Nufit'];
disp(header)
disp(N)
Here is the error:
Error using optimoptions (line 114)
Invalid solver specified. Provide a solver name or handle
(such as 'fmincon' or @fminunc).
Type DOC OPTIMOPTIONS for a list of solvers.
Error in bestfitever (line 20)
options = optimoptions('ga', 'PopulationSize',PopSz,
'InitialPopulationMatrix',randi(1E+4,PopSz,Parms)*1E-4,
'MaxGenerations',2E3, 'PlotFcn',@gaplotbestf,
'PlotInterval',1);

Answers (0)

Products


Release

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!