Coding: Simpson'S 1/3 Rule
Coding: Simpson'S 1/3 Rule
Example
6 1
Evaluate ∫0 𝑑𝑥 by applying Simpson’s 1/3rd rule by dividing into six equal
1+𝑥 2
parts.
𝑏−𝑎 6−0
Solution: a = 0 b=6 h= = =1
𝑛 6
x 0 1 2 3 4 5 6
y 1 0.5 0.2 0.1 0.058 0.038 0.027
ℎ
I = [(𝑦0 + 𝑦6 ) + 4(𝑦1 + 𝑦3 + 𝑦5 ) + 2(𝑦2 + 𝑦4 )]
3
1
I = [(1 + 0.027) + 4(0.5 + 0.1 + 0.038) + 2(0.2 + 0.058)]
3
I = 1.365
Program Description
1. Write the function whose definite integral is to be calculated.
2. Set the precision.
3. n is for subintervals and i is for loop.
4. Get the limits of integration.
5. Get the no. of subintervals.
6. Get the width of the subintervals.
7. Write a loop to evaluate x0,…….xn and y0,……yn.
8. Store them in arrays.
9. Write a loop to evaluate 4*(y1+y2+y3+y5+………+yn-1).
10. Write a loop to evaluate 4*(y1+y2+y3+y5+………+yn-1)
+2(y2+y4+y6+…...+yn-2).
11.Apply formula of Simpson’s 1/3rd rule.
Input
Output
Formula
ℎ
I = [(𝑦0 + 𝑦𝑛 ) + 4(𝑦1 + 𝑦3 + 𝑦5 + ⋯ + 𝑦𝑛−1 ) + 2(𝑦2 + 𝑦4 + ⋯ + 𝑦𝑛−2 )]
3
ℎ
I= [X + 2 E + 4 O]
3