# (Curve fitting) fitting a specific equation to experimental data

Asked by Victor on 2 Mar 2012
Latest activity Commented on by Victor on 2 Mar 2012

Dear all, I have several experimental data and I know the governing nonlinear equation of these data. Now I am trying to find constants/parameters in this equation. But there are 5 unknowns in this equation. Thanks Best regards Victor

## Products

No products are associated with this question.

Answer by Andrei Bobrov on 2 Mar 2012

try nlinfit

Victor on 2 Mar 2012

Dear Andrei,
May I ask you to have a look to the example in:

http://www.mathworks.co.uk/help/toolbox/stats/nlinfit.html

I can not understand the role of part 2: "Generate synthetic data with parameters a = [1;3;2]". Do you have any idea what is the concept behind it?

It is a little bit puzzling for me.
Thanks

Andrei Bobrov on 2 Mar 2012

this is eg

Victor on 2 Mar 2012

Dear Andrei,
Thanks.
May I ask you to follow this simple example. it gives me strange error!

clc
clear
%Suppose matrix of X is experimental data and is composed of x' and y' and matrix a is unknown
%parameters and the known equation is yi = a1 + a2exp(–a3xi)
mdl = @(a,X)(X(:,2)-a(1) + a(2)*exp(-a(3)*X(:,1)));
%arbitrary guess a0 = [2;2;2]:
a = [1;3;2];
x = [0,10,20];
y= [0,5,10];
X=[x',y'];
func = mdl(a,X) ;
a0 = [2;2;2];
[ahat,r,J,cov,mse] = nlinfit(x,y,mdl,a0);
ahat