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

3 次查看(过去 30 天)
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

采纳的回答

Matt J
Matt J 2021-8-2
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 个评论
Matt J
Matt J 2021-8-2
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.

请先登录,再进行评论。

更多回答(1 个)

Matt J
Matt J 2021-7-28
编辑:Matt J 2021-7-28
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 个评论
laura bagnale
laura bagnale 2021-7-29
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 2021-8-2
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);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by