Professional Documents
Culture Documents
Numerical Analysis
Numerical Analysis
Numerical Analysis
NUMERICAL INTEGRATION
Objectives
1.To solve for the area under the curve using the Trapezoidal Rule and the Simpson’s Rule.
2.To implement the Trapezoidal Rule and the Simpson’s Rule using Python programming.
ALGORITHM
#TRAPEZOIDAL RULE
1. Input the function to integrate, lower limit, upper limit, number of strips, and exact value.
2. Define a function using eval ().
3. Calculate the height of each trapezoid as the difference between the upper and lower limits
divided by the number of strips.
4. Initialize the sum variable and x variable to 0.
5. Calculate the values using the trapezoidal formula.
6. Calculate the trapezoidal area using the formula height/2 times the sum.
7. Round the trapezoidal area to three decimal places.
8. Calculate the relative error by using the formula of relative error formula.
9. Output the numerical integral, exact integral, and relative error to the console.
#SIMPSONS RULE
1. Input the function to integrate, lower limit, upper limit, number of strips, and exact value.
2. Define a function using eval ().
3. Calculate the height of each parabola as the difference between the upper and lower limits
divided by the number of strips.
4. Initialize the sum variable and x variable to 0.
5. Calculate the values using the Simpson’s formula.
6. Calculate the Simpson’s area using the formula height/3 times the sum.
7. Round the trapezoidal area to three decimal places.
8. Calculate the relative error by using the formula of relative error formula.
9. Output the numerical integral, exact integral, and relative error.
FLOWCHART
1. Write the Python code which solves for the numerical integral and relative error of the given
function below using the two methods with 10strips.
𝟏𝟎
∫ 𝟔𝒙𝟑 − 𝟕𝒙𝟐 + 𝟖𝒙 − 𝟏𝟎 𝒅𝒙
−𝟏
TRAPEZOIDAL RULE:
# Trapezoidal Rule
import math
def f(x):
return eval(function)
SIMPSONS RULE:
# Simpson Rule
import math
def f(x):
return eval(function)
2. Write the Python code which solves for the numerical integral and relative error of the given
function below using the two methods with 16 strips.
−𝟔
∫ 𝟐𝟏𝒙𝟐 𝒔𝒊𝒏(𝟕𝒙𝟑 − 𝟖)𝒅𝒙
−𝟏𝟓
TRAPEZOIDAL RULE:
# Trapezoidal Rule
import math
def f(x):
return eval(function)
SIMPSONS RULE:
# Simpson Rule
import math
def f(x):
return eval(function)
1. Given the function, fill out the necessary information for the table below.
11
2𝑥 3 + 3𝑥
∫ 𝑑𝑥
𝑥 4 + 3𝑥 2
1
2. Based on the result of the table above, how will you compare the Trapezoidal Rule and the
Simpson’s Rule? What are the similarities and differences of the two methods?
- The similarities about these two methods are that it approximates an integral by using linear
function that solves the error which tells what is more accurate. The difference about the result
shows in the table is that even though they are the same approaching 0 depends on how many
strips you are using. We can see in the table that the error from Simpson’s Rule is much lower
than the trapezoidal rule and much near to approach 0 from 4-20 No. of strips.