plot and fit surface

9 views (last 30 days)
laura bagnale
laura bagnale on 25 May 2021
Commented: laura bagnale on 9 Jun 2021
Hello everyone,
I hope that someone can help me.
I'm trying to plot several points in the space and to fit them so I can get an mathematical formula like this topic https://de.mathworks.com/help/curvefit/polynomial.html#bt9ykh7 "Fit and Plot a Polynomial Surface"
I want to get a quadratic polynomial so I'm trying to use 'poly22' function. This is my code:
X = [0; 1; 1; -1; -1; 0.3]
Y = [0; 1 ; -1; -1; 1; 0.5]
Z = [0.9; 0.3; 0; 0.2; 0.6; 1]
plot3(X,Y,Z,'or')
z = Z;
fitsurface=fit([X,Y],z, 'poly22','Normalize','on')
plot(fitsurface, [X,Y],z)
I obtained this results:
Linear model Poly22:
fitsurface(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2
where x is normalized by mean 0.05 and std 0.9028
and where y is normalized by mean 0.08333 and std 0.9174
Coefficients:
p00 = 0.9097
p10 = -0.2332
p01 = 0.2645
p20 = -1.07
p11 = -0.02071
p02 = 0.5786
But I am not sure about them and the syntax.
Could you help me please?
Thank you a lot!
Laura

Accepted Answer

Mahesh Taparia
Mahesh Taparia on 4 Jun 2021
Hi
The syntax and code which you have used is correct. The above code will fit a 2nd degree polynomial to the given data points and this is what you need.
  17 Comments
laura bagnale
laura bagnale on 9 Jun 2021
I understand.
Thank you very much for the quick answers, the explanation and the support!
Kind Regards,
Laura

Sign in to comment.

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!