Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
3D polynomial fitting

Subject: 3D polynomial fitting

From: scaramanga

Date: 23 Mar, 2011 08:33:05

Message: 1 of 3

Hi to everyone,

I'm trying to fit a 3D dataset with a polynomial regression. I've used the function provided by "John D'Errico" (http://www.mathworks.com/matlabcentral/fileexchange/10065) but without any results.

I have a 3D dataset (x,y,z), as explained by John D'Errico the coefficients are provided by :

polymodel = polyfitn([x y],z,'constant, x, x^2, y, x*y, y^2');

z_interp=polymodel.Coefficients(1)*x + polymodel.Coefficients(2)*x.^2 + polymodel.Coefficients(3)*y + polymodel.Coefficients(4)*x.*y + polymodel.Coefficients(5)*y.^2;

When i try :

figure()
hold on
plot3(x,y,z,'*')
plot3(x,y,z_interp,'r')

I don't get an interpolation of the dataset, but an orthogonal projection in other words, all the z_interp points are in the same level.

Could someone help me ?

Thank you

Subject: 3D polynomial fitting

From: John D'Errico

Date: 23 Mar, 2011 09:49:05

Message: 2 of 3

"scaramanga" wrote in message <imcb81$r0n$1@fred.mathworks.com>...
> Hi to everyone,
>
> I'm trying to fit a 3D dataset with a polynomial regression. I've used the function provided by "John D'Errico" (http://www.mathworks.com/matlabcentral/fileexchange/10065) but without any results.
>
> I have a 3D dataset (x,y,z), as explained by John D'Errico the coefficients are provided by :
>
> polymodel = polyfitn([x y],z,'constant, x, x^2, y, x*y, y^2');
>
> z_interp=polymodel.Coefficients(1)*x + polymodel.Coefficients(2)*x.^2 + polymodel.Coefficients(3)*y + polymodel.Coefficients(4)*x.*y + polymodel.Coefficients(5)*y.^2;
>
> When i try :
>
> figure()
> hold on
> plot3(x,y,z,'*')
> plot3(x,y,z_interp,'r')
>
> I don't get an interpolation of the dataset, but an orthogonal projection in other words, all the z_interp points are in the same level.
>
> Could someone help me ?


I'm confused. Your model is explicitly defined as

   z = a1 + a2*x + a3*x^2 + a4*y + a5*x*y + a6*y^2

as you fit it. (Look at the terms you send in to polyfitn.)

So why would you even remotely expect the expression

   w = a1*x + a2*x^2 + a3*y + a4*x*y + a5*y^2

to predict anything useful in this context?

John

Subject: 3D polynomial fitting

From: scaramanga

Date: 23 Mar, 2011 10:01:05

Message: 3 of 3

Hi John,

Thank you for your answer, I didn't understand what 'constant' stood for, now the model works well thanks to you ;)

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us