MATLAB Answers


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

Zachary Nunn さんによって質問されました 2019 年 8 月 15 日
最新アクティビティ Matt J
さんによって 編集されました 2019 年 8 月 19 日
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)
Thank you,

  1 件のコメント

y = a*exp(-x/b) + c*exp(-x/d) + (1-(a+c))
as equation.

サインイン to comment.

2 件の回答

Answer by Jyotsna Talluri on 19 Aug 2019
 Accepted Answer

You can use a “lsqlin” function from optimization toolbox.
C=[exp(-x/t(2)) exp(-x/t(4)) ones(size(x))];
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
Refer to the below link

  0 件のコメント

サインイン to comment.

Matt J
Answer by Matt J
on 19 Aug 2019
Edited by Matt J
on 19 Aug 2019

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',...
newrelax = fittype('q*exp(-x/r)+ s*exp(-x/(r+d))+(1-(q+s))','options',f3);

  0 件のコメント

サインイン to comment.

Translated by