假設有這麼一組資料,
x=[4 5 6 7 8 4 8 10]';
y=[56 56 56 56 56 60 60 60]';
z=[6 6 6 9 6 19 6 6]';
要求出其平面方程z=C+Ax+By
可以使用MATLAB的regress來進行平面拟合:
X = [ones(size(x,1),1) x y];
b = regress(z,X);
解得:b=[-63.488372093023390;-1.406976744186046;1.402325581395351];
分别對應上式的C A B
在matlab 下畫出平面:
scatter3(x,y,z,'filled')
hold on
xfit = min(x):0.1:max(x);
yfit = min(y):0.1:max(y);
[XFIT,YFIT]= meshgrid (xfit,yfit);
ZFIT = b(1) + b(2) * XFIT + b(3) * YFIT;
mesh (XFIT,YFIT,ZFIT)
![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiInBnauEDOzMTO5YTOzYDMxIDMy8CXwEDNxAjMvwFN0UzNyYzLcd2bsJ2Lc12bj5ycn9Gbi52YuAzcldWYtl2Lc9CX6MHc0RHaiojIsJye.jpg)
轉載于:https://www.cnblogs.com/meadow-glog/p/4038746.html