matlab插值与拟合文档格式.docx
- 文档编号:20024125
- 上传时间:2023-01-16
- 格式:DOCX
- 页数:18
- 大小:433.57KB
matlab插值与拟合文档格式.docx
《matlab插值与拟合文档格式.docx》由会员分享,可在线阅读,更多相关《matlab插值与拟合文档格式.docx(18页珍藏版)》请在冰豆网上搜索。
plot(hours,temps,'
kp'
h,t,'
b'
35
30
25
20
15
10
5
024681012
例2
已知飞机下轮廓线上数据如下,求x每改变0.1时的y值。
X
Y
035791112131415
01.21.72.02.12.01.81.21.01.6
建立M文件plane.m
x0=[035791112131415];
y0=[01.21.72.02.12.01.81.21.01.6];
x=0:
15;
y1=interp1(x0,y0,x,'
nearest'
y2=interp1(x0,y0,x);
y3=interp1(x0,y0,x,'
plot(x0,y0,'
x,y1,'
r'
)
2.5
2
1.5
1
0.5
051015
x,y2,'
x,y3,'
【二维插值】
interp2
ZI=interp2(X,Y,Z,XI,YI,method)插值方式比较示例
用较大间隔产生peaks函数数据点[x,y]=meshgrid(-3:
1:
3);
z=peaks(x,y);
surf(x,y,z)
6
4
-2
-4
-6
-4-4
●产生一个较好的网格
[xi,yi]=meshgrid(-3:
0.25:
●利用最近邻方式插值
zi1=interp2(x,y,z,xi,yi,'
surf(xi,yi,zi1)
●双线性插值方式
zi2=interp2(x,y,z,xi,yi,'
bilinear'
surf(xi,yi,zi2)
●双立方插值方式
zi3=interp2(x,y,z,xi,yi,'
bicubic'
surf(xi,yi,zi3)
●不同插值方式构造的等高线图对比contour(xi,yi,zi1)
3
-1
-3
-3-2-10123
contour(xi,yi,zi2)
contour(xi,yi,zi3)
例3
测得平板表面3*5网格点处的温度分别为:
8281808284
7963616581
8484828586
试作出平板表面的温度分布曲面z=f(x,y)的图形。
建立M文件wendu.m
xx=1:
0.2:
5;
yy=1:
3;
zzz=interp2(x,y,temps,xi'
yi,'
cubic'
mesh(xi,yi,zi);
90
85
80
75
70
65
60
11
例4
某山区测得一些地点的高度如下表所示,平面区域为
该山区的地貌图和等高线图。
比较几种插值方法。
1200x4000,1200y3600
,试作出
建立M文件moutain.m
x=0:
400:
5600;
y=0:
4800;
zz=[370470550600670690670620580450400300100150250;
...
510620730800850870850780720650500200300350320;
650760880970102010501020830900700300500550480350;
740880108011301250128012301040900500700780750650550;
830980118013201450142014001300700900850840380780750;
88010601230139015001500140090011001060950870900930950;
9101090127015001200110013501450120011501010880100010501100;
9501190137015001200110015501600155013801070900105011501200;
143014301460150015501600155016001600160015501500150015501550;
1420143014501480150015501510143013001200980850750550500;
138014101430145014701320128012001080940780620460370350;
13701390141014301440114011101050950820690540380300210;
13501370139014001410960940880800690570430290210150];
figure
(1);
meshz(x,y,z)
2000
1500
1000
500
6000
4000
00
xx=0:
50:
yy=0:
figure
(2)
z1i=interp2(x,y,z,xi,yi'
'
surfc(xi,yi,z1i)
figure(3)
z2i=interp2(x,y,z,xi,yi'
surfc(xi,yi,z2i)
figure(4)
z3i=interp2(x,y,z,xi,yi'
surfc(xi,yi,z3i)
figure(5)
subplot(1,2,1),contour(xi,yi,z2i,10);
subplot(1,2,2),contour(xi,yi,z3i,10);
4500
3500
3000
2500
020004000020004000
【三角测量和分散数据插值】
凸包(ConvexHulls)
loadseamount
plot(x,y,'
.'
markersize'
10)
k=convhull(x,y);
holdon,plot(x(k),y(k),'
-r'
),holdoff
gridon
-47.95
-48
-48.05
-48.1
-48.15
-48.2
-48.25
-48.3
-48.35
-48.4
-48.45
210.8210.9211211.1211.2211.3211.4211.5211.6211.7211.8德洛涅三角(DelaunayTriangulation)
12)
xlabel('
Longitude'
),ylabel('
Latitude'
i
t
e
d
u
a
L
210.8210.9211211.1211.2211.3211.4211.5211.6211.7211.8
Longitude
tri=delaunay(x,y);
holdon,triplot(tri,x,y),holdoff
figure
hiddenon
trimesh(tri,x,y,z)
ylabel('
zlabel('
DepthinFeet'
00
-
F
n
h
p
D
-1000
-2000
-3000
-4000
-5000
-47.8
211.8
Latitude
-48.6210.8
211
211.4
211.2
211.6
[xi,yi]=meshgrid(210.8:
.01:
211.8,-48.5:
-47.9);
zi=griddata(x,y,z,xi,yi,'
[c,h]=contour(xi,yi,zi,'
b-'
clabel(c,h)
-47.9
-40
-3500
-30
-35-030-205
-1500
02
-4000
000
-48.5
火龙尼图形(VoronoiDiagrams)loadseamount
voronoi(x,y)
【数据拟合】
例5
对下面一组数据作二次多项式拟合
x=[0.10.20.4:
.1:
1];
y=[1.9783.286.167.347.669.589.489.3011.2];
A=polyfit(x,y,2);
zz=polyval(A,x);
k+'
x,z,'
12
8
0.10.20.30.40.50.60.70.80.91
例6
用下面一组数据拟合
c(t)abe
0.02kt
中的参数a,b,k。
方法1:
用lsqcurvefit
建立M文件curvefun1.m
functionf=curvefun1(x,tdata)
f=x
(1)+x
(2)*exp(-0.02*x(3)*tdata)
%其中x
(1)=a;
x
(2)=b;
x(3)=k;
输入命令:
tdata=100:
100:
1000;
cdata=1e-03*[4.54,4.99,5.35,5.65,5.90,6.10,6.26,6.39,6.50,6.59];
x0=[0.2,0.05,0.05];
x=lsqcurvefit('
curvefun1'
x0,tdata,cdata)
x=
0.0063-0.00340.2542
方法2:
用lsqnonlin
建立M文件curvefun2.m
functionf=curvefun2(x)
f=x
(1)+x
(2)*exp(-0.02*x(3)*tdata)-cdata
x=lsqnonlin('
curvefun2'
x0)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 拟合
![提示](https://static.bdocx.com/images/bang_tan.gif)