Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Help needed in least square curve fit equation

Asked by Utpal Bakshi on 7 May 2013

Hi all,

I am trying to solve a least square non linear regression with the following data points:

X  1	2	3	4	5	6	7	8	9	10 
Y 2950	2452	2333	2274	2244	2222	2207	2195	2184	2176 

The equation which I want to fit is:

Y=a*exp[-X/b]+c 

a, b and c are constants defined to fit the curve..

Also, as you notice, the Y value decreases with each X, but it will gradually converge and not decrease after a certain value of X. So, I want to extrapolate the curve such that, at very high value of X (X = infinity), function Y converges to its asymptotic value.. In other words, with a certain high number of 'X', the "a*exp[-X/b]" term will tend toward 0, where "c" represents the convergence, and that value of "c" is being taken as final result..

Any type of help is appreciated.. Thanks for your consideration

0 Comments

Utpal Bakshi

Products

No products are associated with this question.

1 Answer

Answer by Matt J on 7 May 2013
Accepted answer

Here's a poor man's approach using FMINSEARCH, assuming,you don't have the Optimization Toolbox. If you do have the toolbox, LSQCURVEFIT would be worth a try.

   %Initial guess
   p0(3)=1000;
   z=[ones(10,1) , -X(:)]\log(Y(:)-p0(3));
   p0(1)=exp(z(1));
   p0(2)=1./z(2);
   %Solve
   p=fminsearch(@(p) norm( p(1)*exp(-X/p(2))+p(3)  - Y),   p0,optimset('MaxFunEvals',100000));
   a=p(1), b=p(2), c=p(3)

1 Comment

Matt J on 7 May 2013

You could also try FEX: fminspleas, which would be well applicable to you, since only one of your parameters, b, is nonlinear.

Matt J

Contact us