## random equation fitting to data set and finding constant parameters

on 22 Jan 2014
Latest activity Commented on by aditi

on 23 Jan 2014

### Amit (view profile)

I have x and y coordinates and I want to fit an equation:

y=a*exp(x^b - 2^b)

## Products

No products are associated with this question.

### Amit (view profile)

on 22 Jan 2014

First make a function that you'll use to fit like this:

```function val = myfunc(par_fit,x,y)
% par_fit = [a b]
```
```val = norm(y - par_fit(1)*exp(x.^2-2^par_fit(2)));
```

Now, find the parameters like:

```my_par = fminsearch(@(par_fit) myfunc(par_fit,x,y),rand(1,2));
```

Amit

### Amit (view profile)

on 23 Jan 2014

I did exactly what I told you earlier, just changed it to the new equation you mentioned.

I get values for a and b as, 5.55e7 and 7.12e7. Very Very high from what you said!!

I posted that plot because I wanted to show you that with limited number of data, you cannot estimate parameters for a very nonlinear function. You have to be very careful, especially in research, on how to determine parameters and then trust it.

on 23 Jan 2014

okay...i will follow previous instructions carefully...maybe i have done something wrong...

and a big thanks to u amit...u were of great help :) will contact u if m stuck again somewher else thanks

on 23 Jan 2014

one more thing...what i found after googling is that in such cases u have to give a specific range for 1 of the parameter... so any idea about that..??

like in above equation if i deliberately want that the b value should lie betweem 0.2 and 2 and then find a and b...how can i do that???

### Matt J (view profile)

on 22 Jan 2014

You might also try FMINSPLEAS. It can take advantage of the fact that y has a linear dependence on one of the parameters 'a'.

Matt J

### Matt J (view profile)

on 22 Jan 2014

If you're new to MATLAB, it makes more sense to start with Amit's solution, which is simpler and which he has given you explicitly.

on 22 Jan 2014

okay... i tried it...but the parameter values are not what i wanted.. so what could have gone wrong..??? also could you please explain the steps of the method which amit told.. i.e what does norm() step is doing...??? why are we subtracting from y???

Matt J

### Matt J (view profile)

on 22 Jan 2014
` norm(y - par_fit(1)*exp(x.^2-2^par_fit(2)))`

measures the distance between the vector y of given curve samples and the vector

`   par_fit(1)*exp(x.^2-2^par_fit(2)) `

of fitted curve samples.

fminsearch tries to find the par_fit(1) and par_fit(2) that minimizes this distance, giving best agreement between y and your parametric curve model.

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