Fit NonLinearLeastSquares to data and constrain curve to pass through point (0,1)

조회 수: 1 (최근 30일)
I have data I need to fit to an equation, which I can do, but I want the equation to pass through point (0,1).
The equation is an exponential y = a*exp(-x/b)+ c*exp(-x/d)+ e
Currently, this is my code:
f3 = fitoptions('Method','NonlinearLeastSquares','Startpoint',[1,100,1,100,1])
newrelax = fittype('q*exp(-x/r)+ s*exp(-x/t)+u','options',f3);
[h,gof] = fit(timeR,stressR,newrelax)
plot(h,timeR,stressR)
Thank you,
-Zach

채택된 답변

Jyotsna Talluri
Jyotsna Talluri 2019년 8월 19일
You can use a “lsqlin” function from optimization toolbox.
t=coeffvalues(h);
C=[exp(-x/t(2)) exp(-x/t(4)) ones(size(x))];
D=y;
A = []; % No inequality constraint
B= []; % No inequality constraint
%Set the specified points in C and D to find equality constraints Aeq, Beq..By substituting (0,1) they turned out to be
Aeq =[1 1 1];Beq=[1];
l=lsqlin(C,D,A,B,Aeq,Beq); %generates coefficients of the curve fitted passing through a specified point
Plot(timeR,C*l);
Refer to the below link

추가 답변 (1개)

Matt J
Matt J 2019년 8월 19일
편집: Matt J 2019년 8월 19일
This answer incorporates Torsten's advice, but I also think you should re-formulate the model to make the exponential terms asymmetric. Otherwise, the solver cannot decide which exponential term belongs to q and which belongs to s.
f3 = fitoptions('Method','NonlinearLeastSquares',...
'Startpoint',[1,100,1,100,1],'Lower',[-inf,-inf,-inf,0]);
newrelax = fittype('q*exp(-x/r)+ s*exp(-x/(r+d))+(1-(q+s))','options',f3);

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by