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

조회 수: 5 (최근 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.
laura bagnale
laura bagnale 2021년 8월 3일
Ok thank you very much for your help and for the explanation!
Kind Regards,
Laura

댓글을 달려면 로그인하십시오.

추가 답변 (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