文档库 最新最全的文档下载
当前位置:文档库 › Maple数值分析第一章

Maple数值分析第一章

Maple数值分析第一章
Maple数值分析第一章

(1.1.1)Maple14数值分析学习笔记

第一章 插值与函数逼近之student 程序包

1.绝对误差、相对误差和有效数字

(1)Student[NumericalAnalysis][AbsoluteError] ‐ compute the absolute error of an approximation ‐‐计算一个逼近(多项式或非多项式)的绝对误差Calling Sequence (调用格式):AbsoluteError(xe, xa, opts)Parameters (参数说明):

xe ‐ realcons; the exact value :精确值(realcons ‐>real constant,实常数)xa ‐ realcons; the approximated value :近似值

opts ‐ (optional) equation(s) of the form digits = value,digits ( environment variable )的值是一个正整数A positive integer ,默认值是10。Example :

with Student NumericalAnalysis :appr :=10.0:exac d 9.8:

AbsoluteError exac ,appr ,digits =5

0.2感悟:整个Maple 有许多模块组成,或者说是程序包,Student 是其中之一,而

NumericalAnalysis 又是其中的一个模块。也可以用面向对象的方法来描述:当然仅仅是对Maple 的猜测性描述,所有的程序包都是一个个类,或许它们有一个公共的基类maple ,也就是说maple 派生出Student 类,Student 类又派生出NumericalAnalysis 类,而AbsoluteError 是NumericalAnalysis 类的一个方法.当我们需要调用AbsoluteError 函数时,就需要加载Student[ NumericalAnalysis]类。

(2)Student[NumericalAnalysis][RelativeError] ‐ compute the relative error of an approximation ‐‐计算相对误差

Calling Sequence : RelativeError(xe, xa, opts)Parameters :

xe ‐ realcons; the exact value

xa ‐ realcons; the approximated value

opts ‐ optional equation(s) of the form keyword = value, where keyword is: digits; the options for computing the relative error of xa

计算相对误差的函数调用方法与上面计算绝对误差函数的调用一致,不再赘述。(3)Student[NumericalAnalysis][NumberOfSignificantDigits] ‐ 计算一个逼近数值的有效精度Calling Sequence :NumberOfSignificantDigits(xe, xa, opts)Parameters :xe

实常数;精确值

(1.1.2)xa 实常数;逼近值

opts

(optional) digits=整数,默认为10

Description :

有效数字的位数必须满足: 0.5 10K s %e and e !0.5 10K s

,其中s 是有效数字的位数,e 是相对误差。 Examples :

with Student NumericalAnalysis :xe d 9.81:xa d 9.63:

NumberOfSignificantDigits xe ,xa

22.多项式内插法

(1)Student[NumericalAnalysis][TaylorPolynomial] ‐ compute a Taylor polynomial approximation ,计算泰勒多项式逼近

Calling Sequence :TaylorPolynomial(f, x, opts) TaylorPolynomial(f, x = x0, opts)Parameters :f algebraic ; expression in the variable x ,代数表达式,其中变量为x 的值x name ; the name of the independent variable in f ,代数表达式f 中的独立变量名x0

realcons ; the point about which the series is expanded ,实常数,泰勒多项式的展开点,缺省为0

opts (optional) 可选表达式keyword = value ,keyword is one of digits, errorboundvar,

order ,extrapolate 。具体解释如下:

digits, errorboundvar, extrapolate 的含义与PolynomialInterpolation 中的含义一致,而order= posint, posint..posint, list(posint),表示多项式的次数,缺省为6。如果order 的值是一个值域或点集,那么其中的所有可用的值都被计算。Description :

‐‐TaylorPolynomial 计算函数f 在x0处的泰勒级数并将其转换为多项式,当然它还可以评价误差。如果x0未指定,代之以0。‐‐TaylorPolynomial 返回值类型:

(1)P ‐‐函数f 在x0处的n=order 次泰勒多项式。

(2)[P,R]‐‐P+R=f ,R 是余项。仅当errorboundvar 给出且extrapolate 未给出时才返回两个值。

(3)[P,R,B ]‐‐当errorboundvar 和extrapolate 都给出时返回三个值。B is a list containing the extrapolated point(s), the value(s) of P at the extrapolated point(s), the value(s) of f at the extrapolated point(s) and the associated error bound(s).Examples :

with Student NumericalAnalysis

:

(1.2.4)

TaylorPolynomial sin x ,x

x K 16 x 3C 1120

x

5TaylorPolynomial sin x ,x ,errorboundvar ='ξ'

x K 16 x 3C 1120 x 5,K 15040

cos ξ x 7

TaylorPolynomial ln x ,x =2,order =3,errorboundvar ='ξ'

ln 2C 12 x K 1K 18 x K 22C 124 x K 23,K 14ξ

TaylorPolynomial sin x ,x ,errorboundvar ='ξ',extrapolate =1.3

x K 16 x 3C 1120 x 5,K 15040

cos ξ x 7, 1.3,0.9647744166,0.9635581854,

0.001245010258

(2)Student[NumericalAnalysis][PolynomialInterpolation] ‐ perform polynomial interpolation on a set of data : 对一系列数据执行多项式内插值。Calling Sequence :PolynomialInterpolation(xy, opts)Parameters :

xy ‐ list(numeric), list(list(numeric, numeric)), list(list(numeric, numeric, numeric)); the data points to be interpolated

opts ‐ equation(s) of the form keyword=value where keyword is one of digits,errorboundvar, extrapolate, function, independentvar, method ; the options for interpolating the data xy 详细说明:

‐‐digits (默认为10)的含义及作用与前面计算误差中的说明一致。

‐‐errorboundvar=name (默认为空):用于指定表示误差界的变量,如errorboundvar='r'。‐‐extrapolate=algebraic, list(algebraic),例如:extrapolate = [0.25, 0.75, 1.25]。【The points to be extrapolated (外推). By default no points are extrapolated. To see the extrapolated values after using the PolynomialInterpolation command, use the ExactValue or ApproximateValue command.】

‐‐function (默认为空):在计算误差的时候用到的精确函数表达式。在

PolynomialInterpolation(xy, opts)中,如果参数xy 是list(numeric)形式的(Maple 理解为x ),那么参数function 是必需的。

‐‐independentvar=name ,指定表示插值多项式的独立变量。如果未指定,以function 中的独立变量代之,若function 为空,则以ind_var 代替。

‐‐method= hermite, lagrange, neville, newton ,指定插值方法。当使用hermite 方法时,参数xy 必须是[[x1, y1, p1], [x2, y2,p2],...]格式的。如果不指定插值方法,默认使用lagrange ;而若参数是list(numeric, numeric, numeric)格式的,调用hermite 方法。

Description :

‐‐PolynomialInterpolation 函数对给定点进行内插值,并将插值结果保存在一个POLYINTERP structure 中,这个structure 可以传递给其他的插值命令以便表示出其内部信息。(RemainderTerm 、Draw 、DividedDifferenceTable 、expand )

(1.2.6)

(1.2.5)Examples :

with Student NumericalAnalysis :

xy :=0,1,12,1,1,1110,32,34,2,78,52,910,3,1110,7

2

,1:

L :=PolynomialInterpolation xy ,independentvar =x ,method =lagrange :expand Interpolant L

1C

73320 x 4K 81831200 x C 225475 x 2K 1722473600 x 3K 3296225 x 5C 22175 x 6K 53225

x 7

xyyp :=1,1.105170918,0.2210341836, 1.5,1.252322716,0.3756968148,2,1.491824698,

0.5967298792:p2:=PolynomialInterpolation xyyp ,method =hermite ,function =e

0.1 x 2

,independentvar =x ,

errorboundvar =ξ,digits =5:

RemainderTerm p2

1720

0.120 e 0.1 ξ

2C 0.0720 ξ2 e 0.1 ξ2C 0.00480 ξ4 e 0.1 ξ2C 0.000064 ξ6 e 0.1 ξ2 x K 1.2

x K 1.52

x K 2.

2

&where 1.%ξand ξ%2.

(3)Student[NumericalAnalysis][CubicSpline] ‐ perform cubic spline interpolation on a set of data ,三次样条插值

Calling Sequence :CubicSpline(xy, opts)Parameters :xy

listlist ; data points, in the form [[x_1,y_1],[x_2, y_2],...], to be interpolated

opts 可选等式 keyword=value , keyword is one of: boundaryconditions (边界条件),

digits, extrapolate, function, independentvar 。

这里只说明一下boundaryconditions = natural, clamped(numeric, numeric),即边界条件可以是自由边界(默认)或固支边界(如clamped(u,v)),分别对应自然三次样条插值和固支三次样条插值。Description :

同PolynomialInterpolation(xy, opts)一样,CubicSpline(xy, opts)对数据点xy 进行三次样条插值并将计算结果保存在一个POLYINTERP 结构中,它可以传递给其他插值命令,以便展示其插值结果,如:Draw 、expand ,这些命令将在后面介绍。

Examples :

with Student NumericalAnalysis :

xy :=0,4.0,0.5,0, 1.0,K

2.0, 1.5,0, 2.0,1.0, 2.5,0,

3.0,K 0.5:

(1.2.7)

p1:=CubicSpline xy ,independentvar =x ,digits =5:expand Interpolant p1

4.K 8.4808 x C 1.9231 x 3

x !0.5K 5.134650 x C 3.4423250K 6.69230 x 2C 6.3846 x 3x !1.021.289380K 58.67538 x C 46.8480 x 2K 11.462 x 3x !1.515.0577950 x K 15.57699750K 2.307730 x 2

K 0.53846 x 3

x !2.0K 64.8079600C 88.904180 x K 39.23090 x 2C 5.6154 x 3x !2.5K 52.442625 x C 52.9809375C 17.30785 x 2K 1.9231 x 3

otherwise

3.POLYINTERP 结构

在前面多项式内插值中介绍TaylorPolynomial 函数返回的是一个多项式,

而PolynomialInterpolation 和CubicSpline 返回的是一个POLYINTERP 结构,无法直接看到插值结果,必须借助其它函数实现。

(1)Draw ‐‐Student[NumericalAnalysis][Draw] ‐ create a plot of a certain aspect of an interpolation structure

Calling Sequence: Draw(p, opts)Parameters:p a POLYINTERP structure

opts

(optional) objects=list ‐> ApproximateValue, BasisFunctions, DataPoints, ExactValue, Function, Interpolant,指明所要画的对象列表

默认值是objects = [DataPoints, Interpolant, Function, ApproximateValue],如果其中之一未给出,就不画。

Description :

Draw 命令绘制POLYINTERP 结构中各个元素的图形,POLYINTERP 结构由PolynomialInterpolation 和CubicSpline 函数生成。所绘制的不同的元素的颜色可以用SetColors 命令修改。Examples :

with Student NumericalAnalysis :

xy :=0,1,12,1,1,1110,32,34,2,78,52,910,3,1110,7

2

,1:

p2:=CubicSpline xy ,independentvar ='x ':Draw p2:

p1:=PolynomialInterpolation xy ,independentvar ='x ',method =lagrange :Draw p1,objects ='BasisFunctions ':

(1.3.2)

(2)Interpolant,expand

Calling Sequence: Interpolant(p, opts)Parameters:p a POLYINTERP structure

opts

(optional) independentvar=name,默认情况下使用的是PolynomialInterpolation 调用中的独立变量。

Description :

Interpolant 命令从一个POLYINTERP 结构中检索插值多项式,这个POLYINTERP 结构是由PolynomialInterpolation 或CubicSpline 创建的。

结合expand 命令,可以得到插值多项式的简约的形式,因为Interpolant 得到的是因式分解形式的插值多项式。Examples :

with Student NumericalAnalysis :xy :=0,4.0,0.5,0, 1.0,K 2.0, 1.5,0, 2.0,1.0, 2.5,0, 3.0,K 0.5:

p1a :=PolynomialInterpolation xy ,function =22K x

cos π x ,method =lagrange ,extrapolate

=0.25,0.75,1.25,errorboundvar =ξ:p1b :=CubicSpline xy ,function =22K x

cos π x ,extrapolate =0.25,0.75,1.25,digits =5:

Interpolant p1a

0.3555555556 x K 0.5 x K 1.0 x K 1.5 x K 2.0 x K 2.5 x K 3.0

K 2.666666667 x x K 0.5 x K 1.5 x K 2.0 x K 2.5 x K 3.0C 1.333333333 x x K 0.5 x K 1.0 x K 1.5 x K 2.5 x K 3.0K 0.04444444444 x x K 0.5 x K 1.0 x K 1.5 x K 2.0 x K 2.5expand Interpolant p1b

4.K 8.4808 x C 1.9231 x 3

x !0.5K 5.134650 x C 3.4423250K 6.69230 x 2C 6.3846 x 3x !1.021.289380K 58.67538 x C 46.8480 x 2K 11.462 x 3x !1.515.0577950 x K 15.57699750K 2.307730 x 2

K 0.53846 x 3

x !2.0K 64.8079600C 88.904180 x K 39.23090 x 2C 5.6154 x 3x !2.5K 52.442625 x C 52.9809375C 17.30785 x 2K 1.9231 x 3

otherwise

(3)ApproximateValue 和ExactValue

Calling Sequence:

ApproximateValue(p)、ApproximateValue(p, pts) ExactValue(p)、ExactValue(p, pts)Parameters:

(1.3.6)

(1.3.7)

(1.3.4)

p 一个 POLYINTERP 结构

pts

(optional) numeric , list(numeric); 一个或是一系列的点,用来计算逼近多项式或精确函数的值

Description :

返回值格式以[[point i , approx i ], [...], ...], i =1..number of points

Examples :

with Student NumericalAnalysis :

xy := 1.0,0.7651977, 1.3,0.6200860, 1.6,0.4554022, 1.9,0.2818186:p1:=PolynomialInterpolation xy ,method =neville ,extrapolate = 1.5:ApproximateValue p1

1.5,0.5118126939

ApproximateValue p1, 1.7,1.8

1.7,0.3980028398, 1.8,0.3400098828xy1d 0,4.0,0.5,0, 1.0,K

2.0, 1.5,0, 2.0,1.0, 2.5,0,

3.0,K 0.5:

p2d PolynomialInterpolation xy ,function =22K x

cos π x ,method =lagrange ,extrapolate

=0.25,0.75,1.25,errorboundvar ='ξ':ExactValue p2

0.25,2.378414230,0.75,K 1.681792830, 1.25,K 1.189207114ExactValue p2,0.5,1.0

0.5,0., 1.0,K 2.

(4)Function 和BasisFunctions

Calling Sequence 、Parameters 和Description :

Function(p),其中p 是一个POLYINTERP 结构,该函数返回POLYINTERP 结构中的精确函数,如果POLYINTERP 中没有给出function ,抛出异常。

BasisFunctions(p),其中p 是一个POLYINTERP 结构,该函数返回POLYINTERP 结构中的插值多项式的基函数。

BasisFunctions(p, indvar),indvar 可选,给出待返回的基函数的独立变量。Examples :

with Student NumericalAnalysis :

xy :=0,4.0,0.5,0, 1.0,K

2.0, 1.5,0, 2.0,1.0, 2.5,0,

3.0,K 0.5:p1:=PolynomialInterpolation xy ,function =22K x

cos π x ,method =lagrange ,extrapolate

=0.25,0.75,1.25,errorboundvar ='ξ':Function p1

22K x cos π x

plot Function p1,x =0..3:BasisFunctions p1,t

(1.3.8)0.0888******* t K 0.5 t K 1.0 t K 1.5 t K 2.0 t K 2.5 t K 3.0,K 0.5333333333 t t K 1.0 t K 1.5 t K 2.0 t K 2.5 t K 3.0,1.333333333 t t K 0.5 t K 1.5 t K 2.0 t K 2.5 t K 3.0,K 1.777777778 t t K 0.5 t K 1.0 t K 2.0 t K 2.5 t K 3.0,1.333333333 t t K 0.5 t K 1.0 t K 1.5 t K 2.5 t K 3.0,K 0.5333333333 t t K 0.5 t K 1.0 t K 1.5 t K 2.0 t K 3.0,0.0888******* t t K 0.5 t K 1.0 t K 1.5 t K 2.0 t K 2.5Draw p1,objects =BasisFunctions :

(5)与计算误差相关的函数

Calling Sequence 、Parameters 和Description :

1. InterpolantRemainderTerm(p, opts),其中p 是一个POLYINTERP 结构,可选项opts 是

以keyword=value 给出,其中keyword 是errorboundvar, independentvar, showapproximatepoly,showremainder 四者之一,前两个参数含义易知,后两个参数是逻辑值true 或false ,控制输出项。该函数返回内插多项式和余项,如果POLYINTERP 结构是由CubicSpline 生成的,就不会返回余项,showremainder=false 。

2.RemainderTerm(p, opts),可选项opts 是以keyword=value 给出,其中keyword 是errorboundvar ,该函数返回插值余项。

3.UpperBoundOfRemainderTerm(p)、UpperBoundOfRemainderTerm(p, pts),该函数返回在指定点处的插值余项的上界。可选项pts 是一个或一组数,指定在何处返回插值余项的上界,若未给出,返回extrapolate 处的插值余项上界。如果p 是三次样条插值函数,必须是固支的。

4.ApproximateExactUpperBound(p)、ApproximateExactUpperBound(p, pts),该函数返回指定点处的插值、准确值和插值余项上界,pts 用于指定位置。返回值列表[pts, approximate values, exact values, upper bounds]。

Examples :

with Student NumericalAnalysis :xy :=0,4.0,0.5,0, 1.0,K 2.0, 1.5,0, 2.0,1.0, 2.5,0, 3.0,K 0.5:

p1:=PolynomialInterpolation xy ,function =22K x

cos π x ,method =lagrange ,extrapolate

=0.25,0.75,1.25,errorboundvar =ξ:InterpolantRemainderTerm p1

0.3555555556 x K 0.5 x K 1.0 x K 1.5 x K 2.0 x K 2.5 x K 3.0

K 2.666666667 x x K 0.5 x K 1.5 x K 2.0 x K 2.5 x K 3.0C 1.333333333 x x K 0.5 x K 1.0 x K 1.5 x K 2.5 x K 3.0K 0.04444444444 x x K 0.5 x K 1.0 x K 1.5 x K 2.0 x K 2.5,

15040 K 22K ξ ln 27 cos π ξK 7 22K ξ ln 26

sin π ξ πC 21 2

2K ξ

ln 25 cos π ξ π2C 35 22K ξ ln 24 sin π ξ π

3

(1.3.14)

(1.3.13)

K 35 22K ξ

ln 23

cos π ξ π4

K 21 2

2K ξ

ln 22

sin π ξ π

5

C 7 2

2K ξ

ln 2 cos π ξ π6

C 22K ξ

sin π ξ π7

x x K 0.5 x K 1.0 x

K 1.5 x K 2.0 x K 2.5 x K 3.0 &where 0.%ξand ξ%3.0RemainderTerm p1

15040

K 22K ξ ln 27 cos π ξK 7 22K ξ ln 26

sin π ξ πC 21 22K ξ ln 25 cos π ξ π2C 35 22K ξ ln 24 sin π ξ π3K 35 22K ξ

ln 23

cos π ξ π4

K 21 2

2K ξ

ln 22

sin π ξ π

5

C 7 2

2K ξ

ln 2 cos π ξ π6

C 22K ξ

sin π ξ π7

x x K 0.5 x K 1.0 x

K 1.5 x K 2.0 x K 2.5 x K 3.0 &where 0.%ξand ξ%3.0UpperBoundOfRemainderTerm p1

0.25,1.793805001,0.75,0.4892195457, 1.25,0.2717886365UpperBoundOfRemainderTerm p1, 1.7,1.1

1.7,0.2519320805, 1.1,0.1786893829

ApproximateExactUpperBound p1

0.25,2.685058594,2.378414230,1.793805001,0.75,K 1.746582031,K 1.681792830,0.4892195457, 1.25,K 1.166503906,K 1.189207114,0.2717886365

(6)DataPoints 与AddPoint 、NevilleTable 和DividedDifferenceTable Calling Sequence 、Parameters 和Description :

1.DataPoints(p);p 是一个POLYINTERP 结构,该函数返回其中的插值数据点。

2.AddPoint(p, pts)、AddPoint(p, pts, bcs);该函数向一个POLYINTERP 结构中插入新的插值点并返回一个POLYINTERP 结构。其中pts 以numeric , list(numeric, numeric), list(numeric, numeric,numeric)格式给出新增的插值点;bcs 以list(numeric, numeric)的格式给出,如

果POLYINTERP 结构是由CubicSpline 给出的,且不是自由三次样条插值,该选项需要给出以确定边界条件。

3.NevilleTable(p)、NevilleTable(p, pt);其中p 是一个POLYINTERP 结构,必须是用Neville 插值法创建的;可选项pt 是一个数字或字符,指定一点或是独立变量来计算Neville table 。

4.DividedDifferenceTable(p)、DividedDifferenceTable(p, pt);该函数用于计算均差表,其中pt 只能是数值。p 必须是用Newton 或Hermite 方法创建的。

Examples :

with Student NumericalAnalysis :

xy d 1.0,0.7651977, 1.3,0.6200860, 1.6,0.4554022, 1.9,0.2818186:p1:=PolynomialInterpolation xy ,independentvar =x ,method =lagrange :DataPoints p1

1.0,0.7651977, 1.3,0.6200860, 1.6,0.4554022, 1.9,0.2818186

(1.3.18)

(1.3.15)

(1.3.17)

(1.3.16)

p2:=PolynomialInterpolation xy ,method =neville ,extrapolate = 1.5:

NevilleTable p2,1.5

0.7651977

000.62008600.5233448671

00.45540220.51029680020.5124714781

0.28181860.51326340020.51128566690.5118126939

p2a :=AddPoint p2, 2.2,0.1103623:NevilleTable p2a ,1.5

0.7651977

0000.62008600.5233448671

000.45540220.51029680020.5124714781

00.28181860.51326340020.51128566690.5118126939

0.11036230.51042700020.51373613360.51183021490.5118199942p3d PolynomialInterpolation xy ,independentvar ='x ',method =newton ,digits =5:DividedDifferenceTable p3

0.76520

000.62009K 0.48370000.45540K 0.54897

K 0.10878

0.28182K 0.57860K 0.0493830.065997

p3a d AddPoint p3, 1.8,0.3920223

:DividedDifferenceTable p3a

0.76520

0000.62009K 0.48370

000.45540K 0.54897K 0.10878

00.28182K 0.57860K 0.0493830.0659970

0.39202

K 1.1020

K 2.6170

K 5.1352K 6.5015

相关文档
相关文档 最新文档