MATLAB Answers

Utpal Bakshi

Help needed in least square curve fit equation

Asked by Utpal Bakshi
on 7 May 2013
Accepted Answer by Matt J

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:


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



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
   z=[ones(10,1) , -X(:)]\log(Y(:)-p0(3));
   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

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

Join the 15-year community celebration.

Play games and win prizes!

Learn more
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

MATLAB Academy

New to MATLAB?

Learn MATLAB today!