Lsqcurvefit nonlinear model: experimental data with model prediction
5 次查看(过去 30 天)
显示 更早的评论
Hello, I am trying to fit a curve with non linear model (as shown in the caption). I used lsqcurvefit. The fitted curve is bad. How can I get a better fit and another question how can i fit two data simultaneously (same xdata but different ydata, for each ydata same function but i just want to change the value "80"). Thank you in advance. (the data is in attachment)
figure;
A=importdata('ouss.xlsx');
xdata = ...
(A(:,1));
ydata = ...
(A(:,2));
%%
% Create a simple exponential decay model.
fun = @(x,xdata)(x(1)*exp(-(x(2)*(80-x(4)))/(x(3)+80-x(4))))...
./(1+(xdata*(x(1)*exp(-(x(2)*(80-x(4)))/(x(3)+80-x(4))))./x(6)).^(1-x(5)));
%%
% Fit the model using the starting point
x0 = [2e+05,12.3,10.12,335,0.37,12.3];
% x0 = [1,1,1,1,1,1];
options = optimoptions('lsqcurvefit','Algorithm','levenberg-marquardt','Display','iter','TolX', 1e-20, 'TolFun', 1e-20, 'MaxFunEvals', 40000, 'MaxIter', 4000000);
lb = [1 1 1 1 0 1];
ub = [1e17 100 100 1000 1 1e9];
[x] = lsqcurvefit(fun,x0,xdata,ydata,lb,ub,options)
%%
% Plot the data and the fitted curve.
times = linspace(xdata(1),xdata(end));
loglog(xdata,ydata,'ko',times,fun(x,times),'b-')
legend('Data','Fitted exponential')
title('Data and Fitted Curve')
0 个评论
采纳的回答
Matt J
2019-4-1
编辑:Matt J
2019-4-1
how can i fit two data simultaneously (same xdata but different ydata, for each ydata same function but i just want to change the value "80").
Just concatenate the data together and write a bigger model function with more variables that describes both.
For a small number of fits, however, it's usually not worthwhile.
How can I get a better fit
I find that fitting the log of the data gives better results,
[x] = lsqcurvefit(@(p,xd)log(fun(p,xd)),x0,xdata,log(ydata),lb,ub,options);
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!