Example 1
Integrate the function sin(x) on the interval [a, b] = [0, &pi]. From calculus, you know that the answer is 2. Continue iterating until εstep < 1e-5.
Let h = b - a = π. Then
R0, 0 = T(h) = ½(sin(0) + sin(π))π = 0
Now, for i = 1, 2, ..., we calculate:
i = 1
R1,0 = T(π/2) = 1.5707963267948966192
- (4 ⋅ 1.5707963267948966192 - 0)/3 = 2.0943951023931954923
i = 2
R2,0 = T(π/4) = 1.8961188979370399
- (4 ⋅ 1.8961188979370399 - 1.5707963267948966)/3 = 2.0045597549844210
- (16 ⋅ 2.0045597549844210 - 2.0943951023931955)/15 = 1.9985707318238360
i = 3
R3,0 = T(π/8) = 1.9742316019455508
- (4 ⋅ 1.9742316019455508 - 1.8961188979370399)/3 = 2.0002691699483878
- (16 ⋅ 2.0002691699483878 - 2.0045597549844210)/15 = 1.9999831309459856
- (64 ⋅ 1.9999831309459856 - 1.9985707318238360)/63 = 2.0000055499796705
i = 4
R4,0 = T(π/16) = 1.9935703437723393
- (4 ⋅ 1.9935703437723393 - 1.9742316019455508)/3 = 2.0000165910479355
- (16 ⋅ 2.0000165910479355 - 2.0002691699483878)/15 = 1.9999997524545720
- (64 ⋅ 1.9999997524545720 - 1.9999831309459856)/63 = 2.0000000162880417
- (256⋅2.0000000162880417 - 2.0000055499796705)/255 = 1.9999999945872902
Finally, |1.9999999945872902 - 2.0000055499796705| ≈ 0.00000556, and thus we may halt and our approximation of the integral is 1.9999999945872902 .
Copyright ©2005 by Douglas Wilhelm Harder. All rights reserved.