matlab自带三次样条

上传人:飞*** 文档编号:47390391 上传时间:2018-07-01 格式:PDF 页数:17 大小:160.28KB
返回 下载 相关 举报
matlab自带三次样条_第1页
第1页 / 共17页
matlab自带三次样条_第2页
第2页 / 共17页
matlab自带三次样条_第3页
第3页 / 共17页
matlab自带三次样条_第4页
第4页 / 共17页
matlab自带三次样条_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《matlab自带三次样条》由会员分享,可在线阅读,更多相关《matlab自带三次样条(17页珍藏版)》请在金锄头文库上搜索。

1、matlab 自带三次样条的程序啊 help spline SPLINE Cubic spline data interpolation. YY = SPLINE(X,Y,XX) uses cubic spline interpolation to find YY, the values of the underlying function Y at the points in the vector XX. The vector X specifies the points at which the data Y is given. If Y is a matrix, then the dat

2、a is taken to be vector-valued and interpolation is performed for each column of Y and YY will be length(XX)-by-size(Y,2). PP = SPLINE(X,Y) returns the piecewise polynomial form of the cubic spline interpolant for later use with PPVAL and the spline utility UNMKPP. Ordinarily, the not-a-knot end con

3、ditions are used. However, if Y contains two more values than X has entries, then the first and last value in Y are used as the endslopes for the cubic spline. Namely: f(X) = Y(:,2:end-1), df(min(X) = Y(:,1), df(max(X) = Y(:,end) Example: This generates a sine curve, then samples the spline over a f

4、iner mesh: x = 0:10; y = sin(x); xx = 0:.25:10; yy = spline(x,y,xx); plot(x,y,o,xx,yy) Example: This illustrates the use of clamped or complete spline interpolation where end slopes are prescribed. Zero slopes at the ends of an interpolant to the values of a certain distribution are enforced: x = -4

5、: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,o,xx,ppval(cs,xx),-); See also INTERP1, PPVAL, SPLINES (The Spline Toolbox). matlab 的 spline x = 0:10; y = sin(x); xx = 0:.25:10; yy = spline(x,y,xx); plot(x,y,o,xx,yy) RT ,已知条件是x=0,1,2,3,4,5,6,7,8,9

6、,10,y=0,0.79,1.53,2.19,2.71,3.03,3.27,2.89,3.06,3.19,3.29; 边界条件是f(0)=0.8,f(10)=0.2,要求的是具体的表达式,y=f(x), spline 函数可以实现三次样条插值x = 0:10; y = sin(x); xx = 0:.25:10; yy = spline(x,y,xx); plot(x,y,o,xx,yy) 另外 fnplt csapi这两个函数也是三次样条插值函数,具体你可以help 一下!怎样用 matlab 插值得到函数表达式悬赏分: 5 - 解决时间: 2010-5-9 23:02 x=1:1:10;

7、y=2:2:20; x1=x; y1=interp1(x,y,x1,spline) y1 = 2 4 6 8 10 12 14 16 18 20 然后怎样将所求得的函数表达式表示出来?谢谢!问题补充:首先,谢谢!我在运行上边程序时遇到如下问题,麻烦再帮我解答下,谢谢! pp=interp1(x,y,x1,spline,pp) ? In an assignment A(matrix,:) = B, the number of elements in the subscript of A and the number of rows in B must be the same. Error in

8、= F:mtlab6.5toolboxmatlabpolyfuninterp1.m On line 218 = v(p(k),:) = extrapval; 而 pp=interp1(x,y,x1,spline) pp = 2 4 6 8 10 12 14 16 18 20 可以正常运行。x=1:1:10; y=2:2:20; pp=interp1(x,y,spline,pp) breaks=pp.breaks coefs=pp.coefs 说明:interp1 得到的函数其实是分段函数。函数的全部信息全部都在pp 里让我们看一下其breaks 分量和 coefs 分量 ,他们蕴含着函数表达式

9、,具体涵义如下:假设 coefs 的第 i 行为 a b c d ,breaks 的第 i 和 i+1 个元素为m 和 n 那么在区间 m,n 的函数表达式就是a(x-m)3+b(x-m)2+c(x-m)+d 下面是例子coefs 第一行是 0 0 2 2 ,breaks 前两个元素是1 和 2 就代表在区间 1,2 的函数表达式是2(x-1)+2 _ pp=interp1(x,y,spline,pp) 不是 pp=interp1(x,y,x1,spline,pp) x1 不要,得到的是蕴含了分段多项式函数的结构pp。 你要直接得到在x1 处的值,直接就y1=interp1(x,y,x1,sp

10、line)就可以了, 不要pp 。Matlab 中插值函数汇总和使用说明命令 1 interp1 功能一维数据插值(表格查找)。该命令对数据点之间计算内插值。它找出一元函数f(x)在中间点的数值。其中函数 f(x) 由所给数据决定。x:原始数据点Y:原始数据点xi:插值点Yi:插值点格式(1)yi = interp1(x,Y,xi) 返回插值向量yi,每一元素对应于参量xi,同时由向量x 与 Y 的内插值决定。参量x 指定数据 Y 的点。若 Y 为一矩阵,则按Y 的每列计算。 yi 是阶数为 length(xi)*size(Y,2) 的输出矩阵。(2)yi = interp1(Y,xi) 假定

11、 x=1:N ,其中 N 为向量 Y 的长度,或者为矩阵Y 的行数。(3)yi = interp1(x,Y,xi,method) 用指定的算法计算插值:nearest :最近邻点插值,直接完成计算;linear:线性插值(缺省方式),直接完成计算;spline:三次样条函数插值。对于该方法,命令interp1 调用函数 spline、ppval、mkpp、umkpp。这些命令生成一系列用于分段多项式操作的函数。命令spline 用它们执行三次样条函数插值;pchip :分段三次 Hermite 插值。对于该方法,命令interp1 调用函数 pchip,用于对向量x 与 y 执行分段三次内插值

12、。该方法保留单调性与数据的外形;cubic :与 pchip 操作相同;v5cubic :在 MATLAB 5.0 中的三次插值。对于超出 x 范围的 xi 的分量,使用方法nearest 、linear 、v5cubic 的插值算法,相应地将返回NaN。对其他的方法, interp1 将对超出的分量执行外插值算法。(4)yi = interp1(x,Y,xi,method,extrap) 对于超出 x 范围的 xi 中的分量将执行特殊的外插值法extrap。(5)yi = interp1(x,Y,xi,method,extrapval) 确定超出 x 范围的 xi 中的分量的外插值extra

13、pval,其值通常取NaN 或 0。例 1 1.x = 0:10; y = x.*sin(x); 2.xx = 0:.25:10; yy = interp1(x,y,xx); 3.plot(x,y,kd,xx,yy) 复制代码例 2 1. year = 1900:10:2010; 2. product = 75.995 91.972 105.711 123.203 131.669 150.697 179.323 203.212 226.505 3.249.633 256.344 267.893 ; 4.p1995 = interp1(year,product,1995) 5.x = 1900:

14、1:2010; 6.y = interp1(year,product,x,pchip); 7.plot(year,product,o,x,y) 复制代码插值结果为:1.p1995 = 2.252.9885 复制代码命令 2 interp2功能 二维数据内插值(表格查找)格式(1)ZI = interp2(X,Y,Z,XI,YI) 返回矩阵 ZI,其元素包含对应于参量XI 与 YI (可以是向量、或同型矩阵)的元素,即 Zi(i,j) Xi(i,j),yi(i,j)。用户可以输入行向量和列向量Xi 与 Yi,此时,输出向量Zi 与矩阵 meshgrid(xi,yi) 是同型的。同时取决于由输入矩

15、阵X、Y 与 Z 确定的二维函数Z=f(X,Y) 。参量 X 与 Y 必须是单调的, 且相同的划分格式,就像由命令meshgrid 生成的一样。若Xi 与 Yi 中有在 X 与 Y 范围之外的点,则相应地返回nan(Not a Number)。(2)ZI = interp2(Z,XI,YI) 缺省地, X=1:n 、Y=1:m ,其中 m,n=size(Z) 。再按第一种情形进行计算。(3)ZI = interp2(Z,n) 作 n 次递归计算,在Z 的每两个元素之间插入它们的二维插值,这样,Z 的阶数将不断增加。interp2(Z)等价于 interp2(z,1) 。(4)ZI = inte

16、rp2(X,Y,Z,XI,YI,method) 用指定的算法method 计算二维插值:linear:双线性插值算法(缺省算法);nearest :最临近插值;spline:三次样条插值;cubic :双三次插值。例 3:1.X,Y = meshgrid(-3:.25:3); 2.Z = peaks(X,Y); 3.XI,YI = meshgrid(-3:.125:3); 4.ZZ = interp2(X,Y,Z,XI,YI); 5.surfl(X,Y,Z);hold on; 6.surfl(XI,YI,ZZ+15) 7.axis(-3 3 -3 3 -5 20);shading flat 8.hold

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号