HP Prime and TI-84 Plus CE: Simpson’s Rule
Caption: The Simpson’s
Rule applied on ∫ X^2*e^X dx from X = 1 to 4
Actual value:
543.2632185
The program SIMPRULE approximates the integral of f(X)
∫ f(X) dX = h/3 * ( f(a) + 2*Σf(x_E) + 4*∑f(x_O) + f(b) )
Where:
a = the lower limit
b = the upper limit
n = the number of intervals, n is even
h = (b – a)/n
x_E = a + h*I where I is from 1 to n-1 and I is even
x_O = a + h*I where I is from 1 to n-1 and I is odd
HP Prime Program:
SIMPRULE
EXPORT SIMPRULE()
BEGIN
//
EWS 2016-06-05
HAngle:=0;
// Radians
LOCAL
f;
INPUT({{f,[8]},A,B,N},
"Simpson
Rule",
{"f(X)=","Low:","High:",
"Intervals
(Even):"});
H:=(B-A)/N;
X:=A;
T:=EVAL(f);
X:=B;
T:=EVAL(f)+T;
FOR
I FROM 1 TO N-1 DO
X:=A+I*H;
IF
FP(I/2)==0 THEN
T:=2*EVAL(f)+T;
ELSE
T:=4*EVAL(f)+T;
END;
END;
T:=T*H/3;
RETURN
T;
END;
TI-84 Plus CE Program:
SIMPRULE
Radian:Func
Input "LOW:",A
Input "HIGH:",B
Input "N (EVEN):",N
(B-A)/N→H
A→X:Y₁→T
B→X:Y₁+T→T
For(I,1,N-1)
A+I*H→X
If fPart(I/2)=0
Then
2*Y₁+T→T
Else
4*Y₁+T→T
End
End
T*H/3→T
Disp "INTEGRAL=",T
Examples:
Example 1:
∫ cos^2 X dX from X = 0 to X = π, n = 14
Approximation:
1.570796327
Example 2:
∫ X^2 + 3*X – 6 dX from X = 1 to X = 3, n = 14
Approximation: 8.66666667
Eddie
Source:
Burden, Richard L. and Faires, J. Douglas. “Numerical Analysis” 8th Ed. Thompson Brooks/Cole: Belmont, CA. 2005
This blog is property of Edward Shore, 2016.