实验四插值法

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验四、插值法

插值法是函数逼近的一种重要方法,它是数值积分、微分方程数值解等数值计算的基础与工具,其中多项式插值是最常用和最基本的方法。拉格朗日插值多项式的优点是表达式简单明确,形式对称,便于记忆,它的缺点是如果想要增加插值节点,公式必须整个改变,这就增加了计算工作量。而牛顿插值多项式对此做了改进,当增加一个节点时只需在原牛顿插值多项式基础上增加一项,此时原有的项无需改变,从而达到节省计算次数、节约存储单元、应用较少节点达到应有精度的目的。

一、实验目的

1、理解插值的基本概念,掌握各种插值方法,包括拉格朗日插值和牛顿插值等,注意其不同特点;

2、通过实验进一步理解并掌握各种插值的基本算法。

二、Matlab命令和程序

命令poly:创建一个向量,其分量为一个多项式的系数,该多项式具有给定的根。

命令polyval:求多项式的值,

命令 conv: 创建一个向量,其分量为一个多项式的系数,该多项式是另外两个多项式的积

polyval(C,2>

>> P=poly(2>

P=1 -2

Q=poly(3>

Q=1 -3

>> conv(P,Q>

ans=

1 -5 6

>> polyval(P,2>

ans=

1、拉格朗日插值( 基于N+1个点,计算拉格朗日多项式>

function [C,L]=lagran(X,Y>

%input --X is a vector that contains a list of

abscissasb5E2RGbCAP

% Y is a vector that contains a list of

ordinatesp1EanqFDPw

%output--C is a matrix that contains the coefficient of the lagraneDXDiTa9E3d

% interplatory polynomial

% -- L is a matrix that contains the Lagrange

coefficent polynomialsRTCrpUDGiT

w=length(X>。

n=w-1。

L=zeros(w,w>。

%Form the Lagrange coefficient polynomials

for k=1:n+1

V=1。

for j=1:n+1

if k~=j

V=conv(V,poly(X(j>>>/(X(k>-X(j>>。

end

end

L(k,:>=V。

end

%Determine the coefficiants of the Lagrange interpolating polynomial5PCzVD7HxA

C=Y*L。

2、牛顿插值

function [C,D,Newton]=newpoly(X,Y,p>

%Input -X is a vector that contains a list of abscissasjLBHrnAILg

% -Y is a vector that contains a list of ordinatesxHAQX74J0X

% -p is the

%Output -C is a vector that contains the coefficents of LDAYtRyKfE

% the Newton interpolatory polynomia

% -D is the divided-difference table

% -Newton is the value of Newton interplatory polynomia in pZzz6ZB2Ltk

n=length(X>。

D=zeros(n,n>。

D(:,1>=Y'。

%Use formula to form the divided-difference table

for j=2:n

for k=j:n

D(k,j>=(D(k,j-1>-D(k-1,j-1>>/(X(k>-X(k-j+1>>。end

end

%Determine the coefficient fo the newton interpolating polynomialdvzfvkwMI1

C=D(n,n>。

for k=(n-1>:-1:1

C=conv(C,poly(X(k>>>。

m=length(C>。

C(m>=C(m>+D(k,k>。

End

%Determine the valueof the newton interpolating polynomial at prqyn14ZNXI

Newton=D(n,n>。

for k=(n-1>:-1:1

Newton=Newton*(p-X(k>>+D(k,k>。

End

三、实验任务

1、已知函数表

0.56160 0.56280 0.56401 0.56521

0.82741 0.82659 0.82577 0.82495

用二次拉格朗日插值多项式求时的函数近似值。

解:题目要求我们做二次拉格朗日插值多项式,选取三组数字,选最接近x=0.5635的三个数字为

0.56280 0.56401 0.56521

0.82659 0.82577 0.82495

在MATLAB中输入程序:

>> X=[ 0.56160 0.56280 0.56401 0.56521]。

>> Y=[ 0.82741 0.82659 0.82577 0.82495]。

>> [C,L]=lagran(X,Y>

C =

1.0e+03 *

-1.2982 2.1943 -1.2370 0.2334

L =

相关文档
最新文档