Fit a polynomial function
Mostrar comentarios más antiguos
Does someone know how it is possible to fit a polynomial function whent the x value is a vector? In other words, if we want to fit a polynomial function with output data y and input parameters x where x=[x1,x2,x3,....,xn]. Because until now the only thing that I have found is only if x is a single parameter.
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 21 de Jun. de 2015
0 votos
See my polyfit demo, attached below this image it creates

4 comentarios
the cyclist
el 21 de Jun. de 2015
@IA, I believe she wants a fit of the form
Y = f(X1,X2,...),
not just
Y = f(X)
Image Analyst
el 21 de Jun. de 2015
For a multi-dimensional fit, she can use John D'Errico's polyfitn(): http://www.mathworks.com/matlabcentral/fileexchange/34765-polyfitn
Katerina Rippi
el 21 de Jun. de 2015
Image Analyst
el 21 de Jun. de 2015
Attached is an example. Consider x1 to be the horizontal direction, and x2 to be the orthogonal (vertical) direction. It fits the data (models it) to a 4th order polynomial in both directions. For each (x1, x2) pair, I have a value f(x1,x2) which is the intensity of the image. Then I fit a 2D 4th order polynomial surface to those values.
dpb
el 21 de Jun. de 2015
There are several regression and curve fitting routines if you have the Statistics and/or Curve Fitting toolboxes; if you don't you can use the "backslash" operator that will do a least squares solution to an overdetermined system. In this case you write the explicit model as the design matrix (not forgetting to include the column of Ones for the intercept term, of course) and a vector of the observation values as
X=[ones(length(y),1) x1 x2 ... xN];
and solve as
c=X\y;
where each xi is the (column) vector of the values of the associated independent variable and y is your vector of observations.
For example, if you were to try to fit a model of the form z=f(x,y) with the cross term, you could write
X=[ones(size(z)) x x.*y y];
c=X\z;
Again, the above assumes column vectors x,y,z are the two independent variables and z is the observation. c will be the coefficients of the the model
z=c(1) + c(2)*x + c(3)*x.*y + c(4)*y;
Categorías
Más información sobre Polynomials en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!