大学数值计算方法题目答案

更新时间:2023-05-12 23:37:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

数值计算方法 黄云清编

数值计算方法

Project II solutions:

1.Give the formula of the following methods: Langerange Interpolation、Piecewise Linear Langerange Interpolation and Cubic Spline Interpolation

(1)Langerange Interpolation formula:

Ln(x) yili(x),

i 0n

li(x) (x x0)...(x xi 1)(x xi)...(x xn),i 0,1,...,n(xi x0)...(xi xi 1)(xi xi 1)...(xi xn)

其中基函数满足:

1,i j li(xj) 0,i j,i,j 0,1,...n

Piecewise Linear Langerange Interpolation formula: In yjlj(x),

j 0n

x xj 1,xj 1 x xj x xj 1 j x xj 1lj(x) ,xj x xj 1 xj x 0,x

Cubic Spline Interpolation:

S(x) Si(x),x xi 1,xi ,i 1,...,n

Si(x) aix bix cix di32

其中ai,bi,ci,di为待定系数,共4n个,且满足条件:

数值计算方法 黄云清编

Si(xi) Si 1(xi) ① Si'(xi) Si' 1(xi),i 1,2,...,n 1,

'''' Si(xi) Si 1(xi)

② S''(x0) S''(xn) 0

(2) Give MatLab or C program

langerange函数文件:

function y=lagr(x0,y0,x)

n=length(x0);m=length(x);

for i=1:m

z=x(i);

s=0;

for k=1:n

p=1;

for j=1:n

if j~=k

p=p*(z-x0(j))/(x0(k)-x0(j));

end

end

s=p*y0(k)+s;

end

y(i)=s;

数值计算方法 黄云清编

end

程序:

x0=[2006.01,2006.02,2006.03,2006.04,2006.05,2006.06,2006.07,2006.08,2006.09,2006.10,2006.11,2006.12,2007.01,2007.02,2007.03,2007.04,2007.05,2007.06,2007.07,2007.08,2007.09,2007.10,2007.11,2007.12,2008.01,2008.02,2008.03,2008.04,2008.05,2008.06,2008.07,2008.08,2008.09,2008.10,2008.11,2008.12,2009.01,2009.02,2009.03,2009.04,2009.05,2009.06];

y0=[8.0668 8.0493 8.0035 8.0156 8.0152 8.0067

7.991 7.9733 7.9368 7.9032 7.8652 7.8238 7.7898

7.7546 7.739 7.7247 7.6704 7.633 7.5805 7.5753

7.5258 7.5805 7.4233 7.3676 7.2478 7.1601 7.0752 7.2478 6.9724 6.8971 6.8376 6.8515

6.8307 6.8316 6.8286 6.8424 6.8382 6.8357

6.8341 6.8312 6.8345 6.8332];

x=2005:0.1:2010;

y1=lagr(x0,y0,x);

y2=interp1(x0,y0,x);

y3=spline(x0,y0,x);

z=0*x;

数值计算方法 黄云清编

plot(x,z,x0,y0,'.',x,y1,'r',x,y2,'m',x,y3,'c') axis([2005 2010 -10 10])

gtext('lagr')

gtext('interp1')

gtext('spline')

(3)Plot the figures of the above methods.

本文来源:https://www.bwwdw.com/article/ture.html

Top