Report: Weekly Report (Revision)
Yosua Heru Irawan
2019 - 10 - 23
Compute definite integral using C++ code
1. Problem
Known function as follow:
f (x) = x4 + 2x3
Use the rectangular rule, trapezoidal and simpson 1/3 rule to estimate inte-
gral of the function above from a = 0 to b = 10. After that, compare the
results with exact value of the integral (f (x) = 25000).
2. Numerical Integration
Rectangular rule: " #
n
X
I = ∆x f (a + (∆x × i))
i=1
Trapezoidal rule:
Pn−1
f (x0 ) + 2 i=1f (xi ) + f (xn )
I = (b − a)
2n
Simpson’s 1/3 rule:
n−1
P n−2
P
f (x0 ) + 4 f (xi ) + 2 +f (xn )
i=1,3,5 j=2,4,6
I = (b − a)
3n
1
3. Mistake and correction
No Mistake Correction/Improvement
Code error in determining step size Correction code for determin-
1 in rectangular rule program ( previous ing step size in rectangular rule
code xi = a + dx(i - 0.5)). (current code xi = a+(dx.i).
Previous program only can compute
Improvement code for calcu-
one calculaton for one case (if we want
late case with different num-
2 to calculate integral with 10 diferrent
ber of element (add loop com-
number of element, so we must running
mand).
program 10 times).
4. Results
Figure 1: Numerical results for 1000 elements
2
5. Conclusion
Table 1: Results summary
Method Minimum Error Maximum Error
Rectangular 60.03 95,000
Trapezoidal 3.83e-02 35,000
Simpson’s 1/3 1.33e-08 833.33
Based on these results, the Simpson’s 1/3 rule provides a better approxi-
mation than the other two rules or it can be said that the Simpson 1/3 rule
provides more accurate results.
6. Future plan
Learn to compute numerical differentiation using C++ code.