1 / 10

数学模型实验课(三)

数学模型实验课(三). 插值与三维图形. 一 . 插值( Interpolation) 1. 一般插值: interp1(x,y,xi, ’ linear ’ ) 对数据( x i , y i )使用线性的方法在点 {xi} 插值 . interp2(x,y,z,xi,yi,’ spline ’) 对数据( x i , y i, z i )使用样条在网格 {X,Y} 上插值 . 方法: spline, cubic, nearest, pchip 例: >>x=1:10;y=sin(x);xi=0:0.25:10;

cain-rose
Télécharger la présentation

数学模型实验课(三)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 数学模型实验课(三) 插值与三维图形

  2. 一. 插值(Interpolation) • 1. 一般插值: • interp1(x,y,xi,’linear’) • 对数据(xi, yi)使用线性的方法在点 {xi} 插值. • interp2(x,y,z,xi,yi,’spline’) • 对数据(xi, yi,zi)使用样条在网格 {X,Y} 上插值. • 方法:spline, cubic, nearest, pchip • 例: • >>x=1:10;y=sin(x);xi=0:0.25:10; • >>yi=interp1(x,y,xi,’linear’);plot(x,y,’*’,xi,yi)

  3. 2. 样条插值 • spline(x,y,xi) • 例 1. • >>x=1:10;y=sin(x);xx=0:0.25:10; • >>yy=spline(x,y,xx);plot(x,y,’*’,xx,yy) • 例 2. • >>x=-4:4; • >>y=[0,.15,1.12,2.36,2.36,1.46,.49,.06,0]; • >>cs=spline(x,[0,y,0]);xx=linspace(-4,4,101); • >>plot(x,y,’*’,xx,ppval(cs,xx),’-’)

  4. 例 3.7 一水库上游河段降暴雨.,根据预报测算上游流入水库的流量为Q(t) (102立方米/秒) : t (时) 8 12 16 24 30 44 48 56 60 Q(t) 36 54 78 92 101 35 25 16 13 利用这个预报值估计14:30 和 20:30 时上游流入水库的流量。 假设: 1 已知数据准确。 2 相邻两个时刻之间的流量没有突然的变化。

  5. t=[8,12,16,24,30,44,48,56,60]; • q=[36,54,78,92,101,35,25,16,13]; • t1=8:0.5:60; • q1=interp1(t,q,t1,'linear'); • plot(t,q,'b',t1,q1); • hold on; • q2=interp1(t,q,t1,'spline'); • plot(t,q,'b',t1,q1,t1,q2,'r') • q1 • q2

  6. 二. 三维图形 • plot3: 三维点、线图 • contour: 等高线图 (contour3) • mesh: 网格表面图 (meshc,meshz) • surf: 网格阴影图 (surfc, surfl) • 例 1 • >>t=0:pi/50:10*pi;x=sin(t);y=cos(t); • >>plot3(x,y,t)

  7. 例2 • >>n=-8:0.5:8;m=n’; • >>x=ones(size(m))*n;y=m*ones(size(n)); • >>t=sqrt(x.^2+y.^2)+eps;z=sin(t)./t; • >>mesh(z) • meshc, meshz, surfc, surfl, • contour, contour3 • >>mesh(Z);hold on; contour(Z)

  8. 例3.6 地形模型:平面区域上的海拔高程 h(x, y) • x\y 0 400 800 1200 1600 2000 • 0 370 470 550 600 670 690 • 400 510 620 730 800 850 870 • 800 650 760 880 970 1020 1050 • 1200 740 880 1080 1130 1250 1280 • 1600 830 980 1180 1320 1450 1420 • 2000 880 1060 1230 1390 1500 1500 • 给出这个平面区域内地形的模型。

  9. 3. 插值技术 • x=0:4:20;%给出X轴的坐标 • y=0:4:20; %给出Y轴的坐标 • z=[37 51 65 74 83 88; 47 62 76 88 98 106; … ; 69 87 105 128 142 150];%给出(x,y)点的高程 • [X,Y]=meshgrid(0:1:20,0:1:20);% 给出新的插值坐标 • Z=interp2(x,y,z,X,Y,’spline’);%在新的坐标上进行样条插值 • clf;%清空图形坐标系中的内容 • axis xy;%设置坐标的单位一致 • mesh(X,Y,Z);%用网格画出插值的结果 • hold on%打开在同一坐标系中画图的功能 • contour(X,Y,Z);%画平面等高线 • contour3(X,Y,Z);%画三维等高线

  10. 问题 • P87 11,10, • P327-328 根据“逢山开路”一题中表一的数据绘制这个山区的地形图。

More Related