How to use non-linear regression with two input variables?

2 views (last 30 days)
I have three types of data and all three are matrices of same size. One of them can be expressed as a function of the other two as, Z = aX/ (1 + b * e^(-Y/c)), where X, Y and Z are matrices of same size, say nxm, and I have to find coefficient matrix with a,b & c which would fit the equation. For finding coefficients and fitting them to my data, the code I have written is as follows:
myfun = @(p,Y,X) p(1).*X./(1+p(2).*exp(-Y./p(3)));
param = [3000 0.2 10];
After this I am confused about fitting my data.
Thank you in advance.

Accepted Answer

Star Strider
Star Strider on 14 Nov 2014
You have to engage in a bit of deception to fit two independent variables, because the MATLAB curve fitting functions only allow one independent variable in the argument list.
Combine your ‘X’ and ‘Y’ matrices into one variable:
XY(:,:,1) = X;
XY(:,:,2) = Y;
then change ‘myfun’ to:
myfun = @(p,XY) p(1).*XY(:,:,1)./(1+p(2).*exp(-XY(:,:,2)./p(3)));
I tested this with matrices and it successfully returns a matrix result. I didn’t use it in an actual regression.
  4 Comments
Hema
Hema on 25 Nov 2014
Hi Star Strider,
First of all thanks for such a nice explanation and sorry for the late response. I am sort of new to statistics and your explanation was very helpful for me in understanding the problem in using lsqcurvefit.
Thank you, Hema

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!