MATLAB: Nonlinear least squares regression rountine_lsqcurvefit.

nonlinear least squares regression

I have a problem with lsqcurvefit function, please help me. I would like to fit the experiment data at 3 different values: X1,X2,Y This is my function:
Y = a(1)*X1^a(2)*exp(-a(3)./X2).
Could you please help me how to run lsqcurvefit for finding the parameters?
Thank you so much.

Best Answer

You’re almost there.
First, if you want to fit two independent variables, you have to combine them as a matrix to pass them to your function, then use the individual rows or columns of the matrix in your function.
If X1 and X2 are column vectors:
X = [X1 X2];
Y = @(a,X) a(1)*X(:,1)^a(2).*exp(-a(3)./X(:,2));
If X1 and X2 are row vectors:
X = [X1; X2];
Y = @(a,X) a(1)*X(1,:)^a(2).*exp(-a(3)./X(2,:));
Choose the one that’s appropriate to your data.
Also see the documentation on Anonymous Functions.