77范文网 - 专业文章范例文档资料分享平台

第四章 MATLAB的数值计算功能(2)(7)

来源:网络收集 时间:2019-04-09 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

[X,Y] = MESHGRID(x,y) transforms the domain specified by vectors x and y into arrays X and Y that can be used for the evaluation of functions of two variables and 3-D surface plots.

The rows of the output array X are copies of the vector x and the columns of the output array Y are copies of the vector y.

DIFF Difference and approximate derivative.

DIFF(X), for a vector X, is [X(2)-X(1) X(3)-X(2) ... X(n)-X(n-1)]. DIFF(X), for a matrix X, is the matrix of row differences,

[X(2:n,:) - X(1:n-1,:)].

DIFF(X), for an N-D array X, is the difference along the first

non-singleton dimension of X.

DIFF(X,N) is the N-th order difference along the first non-singleton dimension (denote it by DIM). If N >= size(X,DIM), DIFF takes successive differences along the next non-singleton dimension.

([FX,FY] = GRADIENT(F,HX,HY), when F is 2-D, uses the spacing specified by HX and HY. HX and HY can either be scalars to specify the spacing between coordinates or vectors to specify the coordinates of the points. If HX and HY are vectors, their length must match the corresponding dimension of F.)

(QUIVER(X,Y,U,V) plots velocity vectors as arrows with components (u,v)

at the points (x,y). The matrices X,Y,U,V must all be the same size and contain corresponding position and velocity components (X and Y can also be vectors to specify a uniform grid). QUIVER automatically

scales the arrows to fit within the grid.)

GRADIENT Approximate gradient.

[FX,FY] = GRADIENT(F) returns the numerical gradient of the

matrix F. FX corresponds to dF/dx, the differences in the

x (column) direction. FY corresponds to dF/dy, the differences in the y (row) direction. The spacing between points in each direction is assumed to be one. When F is a vector, DF = GRADIENT(F) is the 1-D gradient.

[FX,FY] = GRADIENT(F,H), where H is a scalar, uses H as the

spacing between points in each direction.

[FX,FY] = GRADIENT(F,HX,HY), when F is 2-D, uses the spacing

specified by HX and HY. HX and HY can either be scalars to specify

the spacing between coordinates or vectors to specify the

coordinates of the points. If HX and HY are vectors, their length

must match the corresponding dimension of F.

六. 插值: (Interpolation) 在已知数据之间计算估计值的过程。

1. 一维插值(1D Interpolation)

由interp1实现,用多项式技术计算插值点。

Yi=interp1(x,y,xi,method) y—函数值矢量, x—自变量取值范围,

xi—插值点的自变量矢量, Method—插值方法选项。

MATLAB6.1的4种插值方法: *临近点插值:method= ‘nearest’ *线性插值: method= ‘linear’ *三次样条插值:method= ‘spline’

*立方插值: method= ‘pchip’ or ‘cubic’

选择插值方法时主要考虑因素: 运算时间、占用计算机内存和插值的光滑程度。比较:

运算时间、 占用计算机内存 光滑程度。

*临近点插值: 快 少 差 *线性插值: 稍长 较多 稍好 *三次样条插值: 最长 较多 最好 *立方插值: 较长 多 较好

例1:一维插值函数插值方法的对比。 x=0:10; y=sin(x);

xi=0:0.25:10;

strmod={'nearest', 'linear', 'spline', 'cubic'} %将插值方法定义为单元数组 str1b={'(a) method=nearest', '(b) method=linear',...

'(c) method=spline', '(d) method=cubic'} %将图标定义为单元数组 for i=1:4

yi=interp1(x,y,xi,strmod{i}); subplot(2,2,i)

plot(x,y, 'ro' ,xi,yi, 'b'),xlabel(str1b(i)) end

strmod =

'nearest' 'linear' 'spline' 'cubic' 例2: 三次样条插值 x0=0:10; y0=sin(x0); x=0:.25:10;

y=spline(x0,y0,x); plot(x0,y0,'or',x,y,'k') 与interp1结果一样

2. 二维插值(2D Interpolation)

用于图形图象处理和三维曲线拟合等领域,由interp2实现,一般格式为:

ZI=interp2(X,Y,Z,XI,YI,method) X,Y—自变量组成的数组,尺寸相同。 XI,YI—插值点的自变量数组 Method—插值方法选项,4种 *临近点插值:method= ‘nearest’

*线性插值: method= ‘linear’ 该方法是interp2函数的缺省方法 *三次样条插值:method= ‘spline’

*立方插值: method= ‘pchip’ or ‘cubic’ 例1:二维插值4种方法的对比。

[x,y,z]=peaks(7); figure(1), mesh(x,y,z) [xi,yi]=meshgrid(-3:0.2:3,-3:0.2:3); z1=interp2(x,y,z,xi,yi,'nearest'); z2=interp2(x,y,z,xi,yi,'linear'); z3=interp2(x,y,z,xi,yi,'spline'); z4=interp2(x,y,z,xi,yi,'cubic'); figure(2), subplot(2,2,1) mesh(xi,yi,z1) title('nearest') subplot(2,2,2) mesh(xi,yi,z2) title('linear') subplot(2,2,3) mesh(xi,yi,z3) title('spiine') subplot(2,2,4) mesh(xi,yi,z4) title('cubic')

3. 多维插值: (3D Interpolation)

包括三维插值函数interp3和多维插值函数interpn,函数调用格式与一、二维插值基本相同。

VI=interp3(X,Y,Z,V,XI,YI,ZI,method) 其中: X,Y,Z—自变量组成的数组;

V—三维函数数组

XI,YI,ZI—插值点的自变量数组 Method - 插值方法选项。

(FLOW A simple function of 3 variables.

FLOW, a function of three variables, is the speed profile of a submerged jet within a infinite tank. FLOW is useful for demonstrating SLICE and INTERP3.)

(SLICE(X,Y,Z,V,XI,YI,ZI) draws slices through the volume V along the surface defined by the arrays XI,YI,ZI.)

(SHADING FLAT sets the shading of the current graph to flat. SHADING INTERP sets the shading to interpolated.

SHADING FACETED sets the shading to faceted, which is the default.)

例1:三维插值实例。

[x,y,z,v]=flow(10); %三变量无限大容器淹没射流场的速度剖面图 figure(1),

slice(x,y,z,v,[6 9.5],2,[-2 .2]) %在X=6,9.5, Y=2, z=-2, 0.2五处取切面 [xi,yi,zi]=meshgrid(.1:.25:10,-3:.25:3,-3:.25:3);

vi=interp3(x,y,z,v,xi,yi,zi); %全场沿坐标面插值 figure(2),

slice(xi,yi,zi,vi,[6 9.5],2,[-2 .2]) %切面插值 shading flat

FLOW A simple function of 3 variables.

FLOW, a function of three variables, is the speed profile of a submerged jet within a infinite tank. FLOW is useful for demonstrating SLICE and INTERP3.

There are several variants of the calling sequence: V = FLOW; produces a 50-by-25-by-25 array.

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库第四章 MATLAB的数值计算功能(2)(7)在线全文阅读。

第四章 MATLAB的数值计算功能(2)(7).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/582115.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: