필터 지우기
필터 지우기

Lsqcurvefit nonlinear model: experimental data with model prediction

조회 수: 1 (최근 30일)
Kaouthar Kaouthar
Kaouthar Kaouthar 2019년 4월 1일
편집: Matt J 2019년 4월 1일
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')

채택된 답변

Matt J
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
Kaouthar Kaouthar
Kaouthar Kaouthar 2019년 4월 1일
Thank you for your quick response.
Thank you for the response of the first question.
As for the second one, in order to better visualize the error between the experimental curve and the fitted one, i move to a log scale and the difference is still very big.
I attached the result.
Thank you.
Matt J
Matt J 2019년 4월 1일
편집: Matt J 2019년 4월 1일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Least Squares에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by