Compound Trapezoidal Method for Numerical Integration

by admin in , , on April 30, 2019

This code calculates the Numerical Integration of a given equation on a predefined interval using Compound Trapezoidal Method. This codes uses variable step size and gives good accuracy.

Code Outputs:

  • Chart of Integration History
  • Chart of Residuals
  • Printed values of Final Iteration value, Accuracy and Number of Iterations.

Result is: 0.86362, Accuracy: 9.8688e-05, NO Iterations: 25

Input Requirements:

  • The equation you intended to integrate
  • Integration interval [a b].
  • predefined error (default 0.0001).
  • Maximum number of iterations (default 10000).

About The Method:

Trapezoidal Rule:

The function f(x) (in blue) is approximated by a linear function (in red).

In mathematics, and more specifically in numerical analysis, the trapezoidal rule (also known as the trapezoid rule or trapezium rule) is a technique for approximating the definite integral.

The trapezoidal rule works by approximating the region under the graph of the function  as a trapezoid and calculating its area. It follows that

The trapezoidal rule may be viewed as the result obtained by averaging the left and right Riemann sums, and is sometimes defined this way.

Illustration of ‘chained trapezoidal rule’ used on an irregularly-spaced partition of [a, b]. The integral can be even better approximated by partitioning the integration interval, applying the trapezoidal rule to each subinterval, and summing the results. In practice, this ‘chained’ (or ‘composite’) trapezoidal rule is usually what is meant by ‘integrating with the trapezoidal rule’. Let {xk} be a partition of [a, b] such that a = x0 < x1 < … < xn-1 < xn = b and dxk be the length of the k-th subinterval (that is, dxk = xk – xk-1), then

The approximation becomes more accurate as the resolution of the partition increases (that is, for larger N, dxk decreases). When the partition has a regular spacing, as is often the case, the formula can be simplified for calculation efficiency.

Non-uniform Grid:

When the grid spacing is non-uniform, one can use the formula

Uniform Grid:

For a domain discretized into N equally spaced panels, considerable simplification may occur. Let

the approximation to the integral becomes

which requires fewer evaluations of the function to calculate.

 

0 Sale

Share Now!

Release Information

  • Price
    :

    $4.99

  • Released
    :

    April 30, 2019

  • Last Updated
    :

    May 28, 2019

Share Your Valuable Opinions