In MATLAB, you can use the polyfitn
function from the Curve Fitting Toolbox to perform multivariate linear least-squares fitting.
Here's an example:
main.m208 chars11 lines
In this example, polyfitn
fits a linear model of the form y = p(1)*x1 + p(2)*x2 + p(3)
to the data.
You can then use the p
coefficients to predict the response variable y
for new values of x1
and x2
:
main.m160 chars7 lines
Note that polyfitn
can handle higher-order polynomial models and also allows you to specify constraints on the coefficients. See the MATLAB documentation for more information.
gistlibby LogSnag