Polynomial fitting with multiple independent variables

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

 Respuesta aceptada

Matt J
Matt J el 27 de En. de 2014

12 comentarios

in my case it is 4D problem (3 independent and 1 dependent value)
Matt J
Matt J el 27 de En. de 2014
Editada: Matt J el 27 de En. de 2014
Are you saying that invalidates my answer somehow? As far as I can tell, polyfitn is applicable to any dimension.
there are only 2D examples (3D max)
Matt J
Matt J el 27 de En. de 2014
Even if the examples are 2D, the tool is applicable to higher.
could you please be more specific? Let's say I have P(1,2,3,4,5), T(5,4,3,2,1), C(-2,-1,0,1,2), then P(1)T(1)C(1)=R(1)=2; R(2)=4 ; R(3)=6 R(4)=8 ; R(5)=10.
Matt J
Matt J el 27 de En. de 2014
Editada: Matt J el 27 de En. de 2014
I don't know what your notation means. What is the form of the polynomial you are trying to fit? Do you want all possible polynomial terms in 3 independent variables. If so
p=polyfitn([p(:),t(:),c(:)],r(:), 3);
Undefined function 'polyfitn' for input arguments of type 'double'.
Matt J
Matt J el 28 de En. de 2014
Probably because you didn't download it from the link I gave you.
great! many thanks! I have only few questions: what is the "default model" (all 3 polynomial terms)? In the output I've got 20 coefficients... Is it possible to do curve fitting or somehow visualize the results with these 3independent+1dependent variables?
Matt J
Matt J el 28 de En. de 2014
Editada: Matt J el 28 de En. de 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.
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
Matt J el 29 de En. de 2014
I see that there is a polyvaln.m that comes with the POLYFITN toolbox.

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 27 de En. de 2014
Editada: Andrei Bobrov el 27 de En. de 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.

2 comentarios

so what is the expression for function?
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
3 quadratic terms
three cross terms
The coefficients will be in that order in the return vector. You can reorder in whatever order suits you.

Iniciar sesión para comentar.

Categorías

Más información sobre Linear and Nonlinear Regression en Centro de ayuda y File Exchange.

Preguntada:

el 27 de En. de 2014

Comentada:

el 29 de En. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by