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

3 ビュー (過去 30 日間)
laura bagnale
laura bagnale 2021 年 7 月 28 日
コメント済み: laura bagnale 2021 年 8 月 3 日
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 Center および File ExchangeGet 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