Trapezoidal Rule for Numeric Integration
Dr. Kevin G. TeBeest
Kettering University
> 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.)
> Digits := 20 ;
> a := 0.0 ;
> b := Pi ; (NOTE: Recall that in Maple, the number pi is Pi, not pi and not PI.)
> f := x > evalf( sin(x) ) ;
> Subintervals := 10 ;
Subintervals := 10
> Sections := Subintervals ;
> h := evalf( ( b − a ) / Subintervals ) ;
> 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 ;
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