Professional Documents
Culture Documents
Neumerical Method Exp 5 Raj
Neumerical Method Exp 5 Raj
Experiment Name: Implementation of Trapezoid’s Rule, Simpsons 1/3 Rule and Simpson’s 3/8
Rule in Python.
Objectives:
1. To Familiarize with Trapezoidal, Simpson's 1/3, and Simpson's 3/8 rules in
Python for numerical integration.
2. To Learn Python basics required for implementing integration algorithms.
3. To Solve complex problems using Trapezoidal, Simpson's 1/3, and Simpson's 3/8
rules in Python.
4. To Solve complex problems using Trapezoidal, Simpson's 1/3, and Simpson's 3/8
rules in Python.
5. To Explore Python variables, loops, conditionals, and arrays in integration
problem-solving.
6. Gain insights into how numerical integration methods can be applied to solve
real-world problems in various fields such as physics, engineering, and finance.
7. Explore potential optimizations or improvements in the algorithms to enhance
performance or accuracy.
∫ f ( x ) dx
a
by the sum
n
I =∑ Ai f (xi)
i=o
where the nodal abscissas xi and weights Ai depend on the particular rule used for the
quadrature. All rules of quadrature are divided from polynomial interpolation of the integrand.
Therefore, they work best if f(x) can be approximated by a polynomial. Methods of numerical
integration can be divided into two groups: Newton–Cotes formulas and Gaussian quadrature.
Newton–Cotes formulas are characterized by equally spaced abscissas, and include well-known
methods such as the trapezoidal rule and Simpson’s rule. They are most useful if f(x) has already
been computed at equal intervals, or can be computed at low cost.
Trapezoid Rule: The Trapezoid Rule fits a trapezoid into each subinterval and sums the areas of
the trapezoid to approximate the total integral. This approximation for the integral to an arbitrary
function is shown in the following figure. For each subinterval, the Trapezoid Rule computes the
area of a trapezoid with corners at ( x i ,0 ) , ( x i +1 , 0 ) ,( x i , f ( xi ) ¿ and ¿, which is
f ( x i ) +f (x i+1)
h
2
Trapezoidal rule:
Output:
Simpson's 1/3 Rule: Simpson’s 1/3 rule can be obtained from Newton–Cotes formulas with n = 2;
that is, by passing a parabolic interpolant through three adjacent nodes.
Implement Code:
Simpson's 1/3 Rule:
Output:
Simpson's 3/8 Rule: In numerical analysis, Simpson's 3/8 rule (method) is a technique for
approximating definite integral of a continuous function.
This method is based on Newton's Cote Quadrature Formula and Simpson 3/8 rule is obtained
when we put value of n = 3 in this formula.
Mathematically, Simpson's 3/8 Rule is represented by:
∫ f (x ) dx ≈ ( 8 )( ) ( )
b
3 b−a 2 a+b a+2 b
[ f(a) + 3 f( ) +3f + f(b)]
a
3 2 2
Implement Code:
Output:
Conclusion:
In this experiment, we implemented three numerical integration methods: Trapezoid’s Rule,
Simpson's 1/3 Rule, and Simpson's 3/8 Rule in Python. These methods provide approximate
solutions to definite integrals, particularly useful when analytical solutions are not feasible.
Through our implementation, we observed that each method has its strengths and limitations.
Trapezoid’s Rule is straightforward and easy to implement but may require more subintervals to
achieve high accuracy compared to Simpson's rules. Simpson's 1/3 Rule and Simpson's 3/8 Rule
offer higher accuracy for smooth functions with fewer subintervals, but the 3/8 rule requires
additional evaluations. The choice of method depends on the function's behavior and the desired
balance between accuracy and computational cost. Overall, this experiment enhances our
understanding of numerical integration techniques and their practical applications in various
scientific and engineering fields.