MATLAB: How to do non-linear regression for three varietals

fitnlm

Hi All,
I have matrix with three variables (x,y,z) I would like to get best non linear regression for these variables using like this equation: Eq=a*x+b*y+c*z+d
How can I get the constants and correlation coefficient?
Thanks in advance,
Riyadh

Best Answer

The equation you posted is linear. Assuming it is a stand-in for a nonlinear equation, the usual way of fitting a function of several variables is to create a matrix of the incependent variables and passing that as one argument to the objective and fitting functions.
Example:
% % % MAPPING: x = xyz(:,1), y = xyz(:,2), z = xyz(:,3), a = b(1), b= B(2), c = b(3), d = b(4)
xyz = [x(:) y(:) z(:)];
Eq = @(b,xyz) b(1).*xyz(:,1) + b(2).*xyz(:,2) + b(3)*zyz(:,3) + b(4);
Then just use them as arguments to whatever fitting function you want (such as nlinfit or lsqcurvefit).