这是别人编的程序,关于曲面拟合的,看不懂 帮我看看有没有错误 ,那个函数可能是写错了
clear;close;
m=3;n=3;p=1;
x=[0 4 8 12 16 20 24 28 32 36];y=[1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1];
[xx,yy]=meshgrid(x,y);
zz=[17.162 17.278 17.409 17.407 17.493 17.503 17.415 17.196 16.853 16.431
15.889 15.995 16.097 16.096 16.171 16.181 16.101 15.906 15.405 15.241
14.651 14.734 14.823 14.822 14.887 14.900 14.825 14.650 14.211 14.076
13.458 13.520 13.598 13.597 13.642 13.647 13.577 13.442 13.061 12.933
12.288 12.341 12.400 12.399 12.136 12.413 13.378 12.261 11.911 11.832
11.153 11.199 11.239 11.239 11.268 11.269 11.218 11.116 10.681 10.763
10.052 10.083 10.117 10.117 10.140 10.134 10.097 10.009 9.801 9.725
8.985 9.013 9.033 9.033 9.050 9.047 9.014 8.939 8.785 8.719
7.962 7.980 7.996 7.995 7.999 7.991 7.960 7.915 7.801 7.736
6.964 6.973 6.987 6.987 6.987 6.983 6.954 6.919 6.842 6.794];
function [SZ]=fit surface(m,n,p,xx,yy,zz)
%m,n are polynomial order, p weighting matrix
close all
X=vanderrow(m);
Y=vanderrow(n);
Y=subs(Y,'x','y');
SXY=X*transpose(Y);
%weighting W
W=ones(m+1,n+1);
XY=SXY.*W;
XY=transpose(SXY(:));
XY=XY(2:length(XY));
%get all coefficients
a=1;
x=xx(:);
Y=YY(:);
z=zz(:);
XY=double(subs(XY));
XY=[ones(length(x).1).XY];
A=pinv(XY)*z.^p;
a=reshape(A,m+1,n+1);
SZ=SXY.*a;
%the symbolic bivariable polynomial to be got by fit
SZ=sum(SZ(:));
%draw a original surface
figure
subplot(2,2,1);
surf(xx,yy,zz);
%colormap([0 0 0]);
title('original surface')
%draw the fit surface
x=xx;y=yy;
fZ=double(subs(SZ));
figure
subplot(2,2,2);
surf(x,y,fZ);
%colormap([0 0 0]);
title('fit surface')
view(3) |