MATLAB: How do i use the nlinfit function when there are two independent variables

nlinfit

v0=b(1).*A.*B/((b(2).*b(3))+(b(3).*A)+(A.*B))
This is my model. I have two independent variables A and B.v0 is the dependent variable. Now can you please help me with writing the line code for this in matlab where i have to use a nlinfit function.
For one independent variable the following code worked:
model=@(b,x) b(1).*substrate./(b(2)+substrate);
initialguess=[1 1];
[beta,R,J,CovB,MSE] = nlinfit(substrate,vo,model, initialguess);
I want to do the same thing for my above equation.Please suggest.
THANK YOU.

Best Answer

You have to pass your independent variable as a single value. If you have two independent variables, simply create a matrix from them, and make corresponding changes in your function:
AB = [A B]; % Assumes A and B are COLUMN vectors
v0=b(1).*AB(:,1).*AB(:,2)/((b(2).*b(3))+(b(3).*AB(:,1))+(AB(:,1).*AB(:,2)))
Make appropriate changes if they are row vectors, or simply transpose the row vectors to column vectors. (The nlinfit function doesn’t care. It just wants your function to return a vector that matches your dependent variable vector dimensions.)
Your call to nlinfit then becomes:
[beta,R,J,CovB,MSE] = nlinfit(AB, ...
Related Question