0% found this document useful (0 votes)
69 views3 pages

Report: Weekly Report (Revision) : Compute Definite Integral Using C++ Code 1. Problem

1. The document summarizes computing the definite integral of the function f(x)=x^4+2x^3 from 0 to 10 using rectangular, trapezoidal, and Simpson's 1/3 rules in C++ code. 2. Mistakes in the original code were corrected, including fixing the step size calculation in the rectangular rule and adding a loop to calculate different numbers of elements. 3. Results showed that Simpson's 1/3 rule provided much more accurate approximations to the exact integral value of 25,000 than the other two methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views3 pages

Report: Weekly Report (Revision) : Compute Definite Integral Using C++ Code 1. Problem

1. The document summarizes computing the definite integral of the function f(x)=x^4+2x^3 from 0 to 10 using rectangular, trapezoidal, and Simpson's 1/3 rules in C++ code. 2. Mistakes in the original code were corrected, including fixing the step size calculation in the rectangular rule and adding a loop to calculate different numbers of elements. 3. Results showed that Simpson's 1/3 rule provided much more accurate approximations to the exact integral value of 25,000 than the other two methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

You might also like