I'm trying to do minimization for two variables in this code to match some output data that I got experimentally. I first tried it with just the lsqcurvefit but I kept getting that the "initial point is a local minimum". So I have tried now to use the MultiStart command with the Global optimization toolbox to get a "better" local minimum (hopefully to find the global minimum). However, upon plotting the results, it is obvious that the fit found for my two variables is no a very good one to my data. I have tried varying the starting point but end up with fits that are just as bad.
black circles is the fit and the colours are my collected data.
Here is my code:
%data=readtable('808nm/data808.xlsx');
X=data{:,2}; Y=data{:,1};options = optimoptions('lsqcurvefit','OptimalityTolerance', 1e-16, 'FunctionTolerance', 1e-16);x0=[10 ;10];lb=[0 0];ub=[10 50];[x,resnorm]=lsqcurvefit(@myfunc,x0,X,Y,lb,ub,options)problem= createOptimProblem('lsqcurvefit','x0',x0,'objective',@myfunc,'lb',lb,'ub',ub,'xdata',X,'ydata',Y);ms=MultiStart('PlotFcns',@gsplotbestf);[xprob,errormulti]=run(ms,problem,2000) figure(1); plot(source5_808(:,2),log(source5_808(:,1)),'b+',source6_808(:,2),log(source6_808(:,1)),'r+',source7_808(:,2),log(source7_808(:,1)),'g+'); title('808nm'); xlabel('Distance (cm)'); ylabel ('Ln(Fluence) (W cm^{-2})'); hold on; xx=2:1:9; plot(X,log(myfunc(xprob,X)),'ko')
and here is my function
% function Y = myfunc(x,X,Y)
Y=((0.2./(4.*pi.*(1./(3.*(x(1)+x(2)))).*X))).*(exp(-1.*((3.*x(1).*(x(1)+x(2))).^(0.5)).*X));returnend
and finally the input file for the X and Y data attached
Best Answer