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

New to MATLAB?

# Help needed in least square curve fit equation

on 7 May 2013

### Matt J (view profile)

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

## Products

No products are associated with this question.

### Matt J (view profile)

on 7 May 2013

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

### Matt J (view profile)

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.