Trapezoidal Rule for Numeric Integration
Dr. Kevin G. TeBeest
Kettering University

PURPOSE:  To approximate a proper integral of function f (x) on the interval [a,b].


> restart ;    (Recall:  It is best to begin each Maple session with restart. This empties Maple's memory, making this a simple way to rerun your Maple session any time you change anything in the code.)

b := Pi

> Digits := 20 ;

Digits := 20

> a := 0.0 ;

a := 0

> b := Pi ;    (NOTE:  Recall that in Maple, the number pi is Pi, not pi and not PI.)

b := Pi

> f := x –> evalf( sin(x) ) ;

f := proc (x) options operator, arrow; evalf(sin(x)...

> Subintervals := 10 ;

Subintervals := 10

> Sections := Subintervals ;

Sections := 10

> h := evalf( ( b − a ) / Subintervals ) ;

h := .31415926535897932385

> TEMP := 0.0 ;

TEMP := 0

> for i from 1 to Sections do   (After each line in this block, hit Shift-Enter)
         X0 := a + h * ( i − 1 ) :   (Recall:   I require my students to use the asterisk as the multiplier operator.)
         X1 := X0 + h :
         TEMP := TEMP + f(X0) + f(X1) :
    od :
> INTEGRAL := h / 2 * TEMP ;

INTEGRAL := 1.9835235375094545034

Here's how to use Maple's int command to evaluate an integral:

> int ( f(x) , x = a .. b ) ;

2.00000000000000000000

Note:   x is called a "dummy variable." This means the result does not depend on the name of the integrating variable. For example,

> int ( f(P) , P = a .. b ) ;

2.00000000000000000000

> int ( f(r) , r = a .. b ) ;

2.00000000000000000000

> int ( f(s) , s = a .. b ) ;

2.00000000000000000000

Question: What happens if we enter

> int ( f(a) , x = a .. b ) ;     Try it.


Dr. Kevin G. TeBeest
Applied Mathematics
Kettering University