Maple Tutorial 10:
Trapezoidal Rule

M.M. Yovanovich

TUTORIAL10.MWS

Trapezoidal Rule for approximate numerical integration of functions.

Use the Maple package student.

> restart:

> with(student);

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> trapezoid(f(x), x = a..b, n);

[Maple Math]

Application of trapezoidal rule to several functions.

> f1:= x-> sin(x):

> intf1:= subs({a = 0, b = Pi}, trapezoid(f1(x), x = a..b, 20));

[Maple Math]

> evalf(%);

[Maple Math]

> int(f1(x), x = 0..Pi);

[Maple Math]

20 panels gives acceptable accuracy.

> f2:= x-> exp(-x)*cos(x)^1/2:

> intf2:= subs({a = 0, b = 1.5}, trapezoid(f2(x), x = a..b, 100)):

> evalf(%);

[Maple Math]

> int(f2(x), x = 0..1.5);

[Maple Math]

100 panels gives acceptable accuracy.

Integration of Bessel functions.

> f3:= x-> BesselJ(0,x):

> intf3:= subs({a = 0, b = 2.45}, trapezoid(x*f3(x), x = a..b, 40)):

> evalf(%);

[Maple Math]

> int(x*f3(x), x = 0..2.45);

[Maple Math]

Integration of error function.

> f4:= x-> erfc(x):

> intf4:= subs({a = 0, b = 2.75}, trapezoid(f4(x), x = a..b, 80)):

> evalf(%);

[Maple Math]

> int(f4(x), x = 0..2.75); evalf(%);

[Maple Math]

[Maple Math]

>