How to set a custom equation to fit 5 points in space by fitsurface?

4 vues (au cours des 30 derniers jours)
laura bagnale
laura bagnale le 28 Juil 2021
Commenté : laura bagnale le 3 Août 2021
Hello everyone,
it would be very nice if someone could help me with this problem.
I have a set of 5 points in space with x, y, z coordinates and I would like to fit them with a surface. Generally I use fitsurf setting the option 'poly22' to get the equation in the secondo order of x and y.
Now I would like to fit them with the equation f(x,y) = ax + by + cxy + d . Is there a way to do it? Can we set the custom equation using fitsurface?
Thank you very much in advance for your answers!
Regards,
Laura

Réponse acceptée

Matt J
Matt J le 2 Août 2021
Another way, which would allow you stay within the framework of the Curve Fitting Toolbox, would be to do a poly22 fit with upper and lower bounds,
lb=-inf(1,6); lb([4,6])=0; ub=-lb; fitsurface=fit([x,y],z, 'poly22','Lower',lb,'Upper',ub)
Linear model Poly22:
fitsurface(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2
Coefficients (with 95% confidence bounds):
p00 = 1.319 (1.215, 1.423)
p10 = -0.0002893 (-0.0003375, -0.0002411)
p01 = -1.19 (-1.37, -1.01)
p20 = 0 (fixed at bound)
p11 = 0.0002666 (0.0001826, 0.0003507)
p02 = 0 (fixed at bound)
  6 commentaires
Matt J
Matt J le 2 Août 2021
This procedure is only necessary for being able to use the Curve Fitting Toolbox but it doesn't affect the fitting procedure, is it correct?
Well, it's a bit less efficient because you have more data to crunch in this case. The most efficient procedure would be the one given in my original answer.
laura bagnale
laura bagnale le 3 Août 2021
Ok thank you very much for your help and for the explanation!
Kind Regards,
Laura

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 28 Juil 2021
Modifié(e) : Matt J le 28 Juil 2021
I can't find "fitsurface" in the Mathworks documentation, but the fit is easy enough to do algebraically.
x=x(:); y=y(:); z=z(:); %ensure column vectors
params=num2cell([x,y,x.*y,x.^0]\z);
[a,b,c,d]=deal(params{:})
  4 commentaires
laura bagnale
laura bagnale le 29 Juil 2021
The point is that I would like to have the possibility to fit the points in space with a surface that I can represent in a graph and to have an estimation of the coefficient through the fitting, like what I did using poly22.
I consider your answer very helpful but I would like also to fit the points with a surface.
Thank you for your help.
Laura
Matt J
Matt J le 2 Août 2021
One you have the coefficients, it is eay to plot the surface.
x=x(:); y=y(:); z=z(:); %ensure column vectors
params=num2cell([x,y,x.*y,x.^0]\z);
[a,b,c,d]=deal(params{:});
fz=@(x,y) ax + by + cxy + d;
fsurf(fz);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange

Tags

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by