
Lsqcurvefit nonlinear model: experimental data with model prediction
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kaouthar Kaouthar
am 1 Apr. 2019
Bearbeitet: Matt J
am 1 Apr. 2019
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 Kommentare
Akzeptierte Antwort
Matt J
am 1 Apr. 2019
Bearbeitet: Matt J
am 1 Apr. 2019
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 Kommentare
Matt J
am 1 Apr. 2019
Bearbeitet: Matt J
am 1 Apr. 2019
I don't think you're going to do better with this model. The exitflag that I received is 1.
[x,resnorm,residual,exitflag,stats] = ...
lsqcurvefit(@(p,xd)log(fun(p,xd)),x0,xdata,log(ydata),lb,ub,options);
That's the best. It means lsqcurvefit thinks it converged.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!