在一丘陵地带测量高程,x和 y方向每隔100米测一个点,得高程如下表,试
插值一曲面,确定合适的模型,并由此找出最高点和该点的高程。
x
y 100 200 300 400 500
100 636 697 624 478 450
200 698 712 630 478 420
300 680 674 598 412 400
-113-
400 662 626 552 334 310
解 编写程序如下:
clear,clc
x=100:100:500
y=100:100:400
z=[636 697 624 478 450
698 712 630 478 420
680 674 598 412 400
662 626 552 334 310]
pp=csape({x,y},z')
xi=100:10:500yi=100:10:400
cz1=fnval(pp,{xi,yi})
cz2=interp2(x,y,z,xi,yi','spline')
[i,j]=find(cz1==max(max(cz1)))
x=xi(i),y=yi(j),zmax=cz1(i,j)
在某海域测得一些点(备喊x,y)处的水深 z 由下表给出,在矩形区域(75,200)
×(-50,150) 内画出海底曲面的图形。
x 129 140 103.5 88 185.5 195 105 157.5 107.5 77 81 162 162 117.5
y 7.5 141.5 23 147 22.5 137.5 85.5 –6.5 -81 3 56.5 –66.5 84 -33.5
z 4 8 6 8 6 8 8 9 9 8 8 9 4 9
解 编写程序如下:
x=[129 140 103.5 88 185.5 195 105 157.5 107.5 77 81 162 162
117.5]
y=[7.5 141.5 23 147 22.5 137.5 85.5 -6.5 -81 3 56.5 -66.5 84
-33.5]
z=-[4 8 6 8 6 8 8 9 9 8 8 9 4
9]
xi=75:1:200
yi=-50:1:150
zi=griddata(x,y,z,xi,yi','cubic')
subplot(1,2,1)
plot(x,y,'*')
subplot(1,2,2)
mesh(xi,yi,zi) 希望凯滚迅对你有帮助,这是插值
某乡镇企业 1990-1996 年的生产利润如下表:
年份 1990 1991 1992 1993 1994 1995 1996
利润(万元) 70 122 144 152 174 196 202
试预测 1997年和 1998 年的利润。
解 作已知数据的的散点图,
-1
x0=[1990 1991 1992 1993 1994 1995 1996]
y0=[70 122 144 152 174 196 202]
plot(x0,y0,'*')
发现该乡镇企业的年生产利润几乎直线上升。
因此,我们可以用 y =a x+a 作为
1 0
拟合函数来预测该乡镇企业未来的年利盯此润。
编写程序如下:
x0=[1990 1991 1992 1993 1994 1995 1996]
y0=[70 122 144 152 174 196 202]
a=polyfit(x0,y0,1)
y97=polyval(a,1997)
y98=polyval(a,1998)
曲面拟合可以按下列步骤进行:1、根据x,y,z数据,可以用cftool拟合工具箱的常用大和函数去拟合,判断(x,y,z)大概符合那个曲面方程。(注:cftool拟合工具箱有时候不一定与实际相符)
2、建立曲面方饥仿简程模型函数,如func=@(a,x) a(1)*x(1)^2+a(2)*x(2)^2,这里x(1)→x,烂裤x(2)→y
3、用 nlinfit()或lsqcurvefit()拟合函数,去拟合模型函数的系数a。
a = nlinfit(x,z,func,a0)
a =lsqcurvefit(func,a0,x,z)
4、计算 z数据值与z拟合值的拟合度,即决定系数R²是否接近于1。愈接近于1其拟合精度也就愈高。
%可洞卖用样条曲面拟合,最好对原数据整理纳凯逗孙肢一下,拟合的代码如下:x0=2.2:0.1:7y0=10:5:30
z0 =[ 0.01210.01180.01290.10980.0103
0.01160.01160.01240.10070.0111
0.01100.01130.01200.09140.0119
0.01050.01110.01160.08200.0128
0.00990.01090.01120.07260.0136
0.00940.01070.01080.06350.0144
0.00900.01050.01050.05470.0151
0.00850.01040.01010.04650.0158
0.00810.01020.00980.03910.0164
0.00780.01010.00960.03250.0170
0.00750.01000.00940.02700.0174
0.00730.00990.00920.02280.0177
0.00720.00990.00910.02000.0179
0.00710.00980.00910.01870.0180
0.00710.00980.00910.01830.0180
0.00710.00980.00910.01790.0180
0.00710.00980.00910.01760.0180
0.00720.00990.00910.01720.0180
0.00720.00990.00910.01690.0180
0.00720.00990.00910.01650.0180
0.00720.00990.00910.01620.0180
0.00720.00990.00910.01590.0180
0.00730.00990.00910.01560.0179
0.00730.01000.00920.01540.0179
0.00740.01000.00920.01510.0178
0.00750.01010.00930.01490.0178
0.00760.01010.00930.01470.0177
0.00770.01020.00940.01440.0177
0.00780.01020.00950.01420.0176
0.00790.01030.00950.01400.0175
0.00810.01040.00960.01390.0174
0.00820.01050.00970.01370.0173
0.00840.01060.00990.01350.0171
0.00860.01070.01000.01340.0170
0.00890.01080.01010.01330.0168
0.00910.01090.01030.01310.0166
0.00940.01110.01050.01300.0164
0.00970.01120.01070.01290.0162
0.01000.01140.01090.01280.0160
0.01040.01150.01110.01280.0157
0.01080.01170.01140.01270.0155
0.01120.01190.01160.01260.0152
0.01160.01210.01190.01260.0148
0.01210.01230.01220.01250.0145
0.01260.01260.01260.01250.0141
0.01310.01280.01290.01250.0138
0.01370.01310.01330.01250.0133
0.01430.01330.01370.01240.0129
0.01500.01360.01410.01240.0124]
sp=csapi({x0 y0},z0)%可得到每片三次样条曲面的系数
fnplt(sp) %可得到拟合曲面的效果图
%也可以用最小二乘曲面拟合,代码为:
[m,n]=size(z0)k=9
C=ones(m*n,1/2*(k+1)*(k+2))
x=reshape(ones(n,1)*x0,m*n,1)
y=reshape(y0'*ones(1,m),m*n,1)
z=reshape(z0,m*n,1)
for j=0:k
for i=0:j
C(:,1/2*(j+1)*(j+2)-j+i)=x.^(j-i).*y.^i
end
end
coefficient=C\z
%做出曲面效果与图1稍有不同,因为采集点较少,所以拟合次数对结果影响很大
syms x y
z=ones(1,1/2*(k+1)*(k+2))sum=0
for j=0:k
for i=0:j
sum=sum+sym(x^(j-i)*y^i)*coefficient(1/2*(j+1)*(j+2)-j+i)
end
end
figureezmesh(sum,[min(x0),max(x0),min(y0),max(y0)])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)