Hello, I have tried to fit my experimental data with a nonlinear model. But the error between the obtained curves is very high. I tried to solve it with lsqnonlin and lsqcurvefit but the exitflag that I received is 1, so i can not get better results with this model. I find then that in some articles, they used line search method. I am not familiar with these types of codes. Can you, please, help me adapting my code to line search algorithm? Otherwise, any ideas to get better fit.
Thank you in advance.
clcclose allclear allfigure;A=importdata('1.xlsx');xdata = ... [A(:,1) A(:,1) A(:,1)];ydata = ... [A(:,2) (A(:,3)) (A(:,4))];%%
% Create the model.
fun = @(x,xdata)[(x(1)*exp(-(x(2)*(357.15-x(4)))/(x(3)+357.15-x(4))))... ./(1.+(xdata(:,1).*(x(1)*exp(-(x(2)*(357.15-x(4)))./(x(3)+357.15-x(4))))./x(6)).^(1-x(5))),... (x(1)*exp(-(x(2)*(367.15-x(4)))./(x(3)+367.15-x(4))))... ./(1.+(xdata(:,1).*(x(1)*exp(-(x(2)*(367.15-x(4)))./(x(3)+367.15-x(4))))./x(6)).^(1-x(5))),... (x(1)*exp(-(x(2)*(377.15-x(4)))./(x(3)+377.15-x(4))))... ./(1.+(xdata(:,1).*(x(1)*exp(-(x(2)*(377.15-x(4)))./(x(3)+377.15-x(4))))./x(6)).^(1-x(5)))];%%% Fit the model using the starting point
% x0 = [1e5;10;10;340;0.2;500];
x0 = [1e4;2;2;300;0.3;6];options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','Display','iter','TolX', 1e-6, 'TolFun', 1e-6, 'MaxFunEvals', 40000, 'MaxIter', 400);lb = [1 1 1 1 0 1];ub = [1e17 100 100 1000 1 1e9];x = lsqcurvefit(fun,x0,[xdata(:,1) xdata(:,1) xdata(:,1)],[ydata(:,1) ydata(:,2) ydata(:,3)],lb,ub,options)%%% Plot the data and the fitted curve.
loglog(xdata(:,1),fun(x,xdata(:,1))) hold onloglog(xdata(:,1),ydata(:,1),'ko')hold onloglog(xdata(:,1),ydata(:,2),'ro')hold onloglog(xdata(:,1),ydata(:,3),'go')legend('Fitted1','Fitted2','Fitted3','Data1','Data2','Data3')title('Data and Fitted Curve')
Best Answer