Trapezoid
and Simpson's Methods on the TI-82/83
|
PROGRAM:TRAPSIMP |
|
|
:Prompt
A,B,N |
|
|
:(B-A)/N |
D
is x |
|
:A |
X
is assuming values of Xo, X1, X2, X3, ...
etc. |
|
:Y1 |
S
is storing the sums for the Simpson method |
|
:Y1 |
T
is storing the sums for the Trapezoid method |
|
:1 |
C
is counter, so that on the even index values, Simpson can be tested |
|
:While
X<B |
|
|
:C+1 |
|
|
:X+D |
Increment
to next X |
|
:S+2Y1 |
Add
f(xi) to both sums |
|
:T+2Y1 |
|
|
:If
C/2=iPart(C/2) |
|
|
:S+2Y1 |
Increment
for Simpson when value is 4f(xi) |
|
:End |
|
|
:S-Y1 |
f(B) has been added in
twice, so subtract it once |
|
:T-Y1 |
|
|
:Disp
“TRAPEZOID ",DT/2 |
Multiply
by h/2 for Trapezoid and display |
|
:Disp
“SIMPSON ",DS/3 |
Multiply
by Ih/3 for Simpson and display |
Test:
; n = 4; i.e.
![]()
Gives
Trapezoid
.2045 and Simpson
.2028