# Polynomial fitting with multiple independent variables

390 views (last 30 days)
Oleksandr on 27 Jan 2014
Commented: Matt J on 29 Jan 2014
Can someone provide example how to perform Polynomial fitting (let's say of 2 or 3-rd order) with multiple independent variables? I have 3 variables: pressure, temperature and concentration (p,t,c) and expectation values of rate of reaction (r) depending on this 3 variables. My question is how to find functional form f(p,t,c)=r and how to perform fitting. (all three variables separetely f(p)=r etc. agree well with linear regresion model).
Thanks a lot

Matt J on 27 Jan 2014

Matt J on 28 Jan 2014
The default model includes all possible terms in a 3rd order 3-variable polynomial. To plot the results, you might use this FEX file
If you fix r to a known constant in your equation f(p,t,c)=r, you obtain an implicit equation for a surface in 3D, which the above will help you plot.
Oleksandr on 29 Jan 2014
thank you! and if I may to ask you what is the command to get the actual (fitted) values of the functions , not the coefficients?
Matt J on 29 Jan 2014
I see that there is a polyvaln.m that comes with the POLYFITN toolbox.

dpb on 27 Jan 2014
Edited: Andrei Bobrov on 27 Jan 2014
Z=zeros(size(p)); % intercept term
X=[Z p t c p.*p t.*t c.*c p.*t p.*c t.*c]; % 2nd order design matrix
c=r\X; % LS solution
You will need a good-sized dataset to have sufficient DOF left after estimating all the terms and while it's a good sign that the "one at a time" plots seem to fit reasonably well that doesn't guarantee a good fit overall.
One would wish that Matlab would have all this built into one of the Toolboxes with a resulting ANOVA table and all but afaict while there are some additional tools in Curve Fitting and Stat toolboxes they really didn't build a general regression model toolset a la SAS, say, unfortunately. You're still on your own for that portion AFAIK.

Oleksandr on 27 Jan 2014
so what is the expression for function?
dpb on 27 Jan 2014
Z p t c p.*p t.*t c.*c p.*t p.*c t.*c
In order, as written above the design matrix is
intercept
3 variables