MATLAB: Curve fitting with more than 2 variables

curvefitting

Hello everyone,
I'm currently trying to curve fit my equations with three independent variables. However, the curve fitting tool in matlab only allow at most 2 independent variable. Any suggestions or help would be strongly appreciated.
Here is my situation:
y = f(x1,x2,x3,Cr,a,b)
x1,x2,x3 are the independent variables(I have it stored in matrix)
y= results (I also have it stored in matrix)
Cr= a constant also in matrix form
a,b= the unknown coefficient that I'm looking for.
y = (1-(exp(-((x3*a)*(x2*b)/(x3*a)+(x2*b))*(1/x1)*(1-Cr))))/(1-(Cr*exp(-((x3*a)*(x2*b)/(x3*a)+(x2*b))*(1/x1)*(1-Cr))))
Thanks

Best Answer

Use lsqnonlin with the f(i) defined as
f(i) = y(i) - (1-(exp(-((x3(i)*a)*(x2(i)*b)/(x3(i)*a)+(x2(i)*b))*(1/x1(i))*(1-Cr(i)))))/(1-(Cr(i)*exp(-((x3(i)*a)*(x2(i)*b)/(x3(i)*a)+(x2(i)*b))*(1/x1(i))*(1-Cr(i)))))
where the matrices y,x1,x2,x3 and Cr are "reshaped" to long vectors.
Best wishes
Torsten.