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

6 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Matt J
Matt J el 2 de Ag. de 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 comentarios
Matt J
Matt J el 2 de Ag. de 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 el 3 de Ag. de 2021
Ok thank you very much for your help and for the explanation!
Kind Regards,
Laura

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 28 de Jul. de 2021
Editada: Matt J el 28 de Jul. de 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 comentarios
laura bagnale
laura bagnale el 29 de Jul. de 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 el 2 de Ag. de 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);

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by