Midpoint (Rectangular) Numerical Integration Matlab Code
by admin in Math, Statistics, and Optimization , MATLAB Family , Numerical Integration on April 30, 2019Choose Your Desired Option(s)
×This code calculates the Numerical Integration of a given equation on a predefined interval using Midpopint Rule (Rectangular Integration). This codes uses variable step size. The method is fast 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.86841, Accuracy: 0.00085441, NO Iterations: 10
Input Requirements:
 The equation you intended to integrate
 Integration interval [a b].
 predefined error (default 0.001).
 Maximum number of iterations (default 1000).
About The Method (Rectangle Method):
In mathematics, specifically in integral calculus, the rectangle method (also called the midpoint or midordinate rule) computes an approximation to a definite integral, made by finding the area of a collection of rectangles whose heights are determined by the values of the function.
Specifically, the interval [a, b] over which the function is to be integrated is divided into N equal subintervals of length h = (ba)/N. The rectangles are then drawn so that either their left or right corners, or the middle
of their top line lies on the graph of the function, with bases running along the xaxis. The approximation to the integral is then calculated by adding up the areas (base multiplied by height) of the N rectangles, giving the formula:
where h = (ba)/N and xn = a + nh.
The formula for xn above gives xn for the Topleft corner approximation.
As N gets larger, this approximation gets more accurate. In fact, this computation is the spirit of the definition of the Riemann integral and the limit of this approximation as n–> inf is defined and equal to the integral of f on [a, b] if this Riemann integral is defined. Note that this is true regardless of which i’ is used, however the midpoint approximation tends to be more accurate for finite n.
The different rectangle approximations
Midpoint approximation Error
For a function f which is twice differentiable, the approximation error in each section (a, a+delta) of the midpoint rule decays as the cube of the width of the rectangle. (For a derivation based on a Taylor approximation, see Midpoint method)
for some xi in (a, a+delta). Summing this, the approximation error for n intervals with width delta is less than or equal to
where n+1 is the number of nodes
in terms of the total interval, we know that n.delta = b – a so we can rewrite the expression:
which is equal to:
for some xi in [a, b].
References:
[1] Leader, Jeffery J. (2004). Numerical Analysis and Scientific Computation. Addison Wesley. ISBN 9780201734997.
[2] Stroud, A. H. (1971). Approximate Calculation of Multiple Integrals. Cliffs, NJ: PrenticeHall Inc.
[3] Briol, FrançoisXavier; Oates, Chris J.; Girolami, Mark; Osborne, Michael A. (20150608). ‘FrankWolfe Bayesian Quadrature: Probabilistic Integration with Theoretical Guarantees’. arXiv:1506.02681 [stat.ML].
[4] Philip J. Davis and Philip Rabinowitz, Methods of Numerical Integration.
[5] George E. Forsythe, Michael A. Malcolm, and Cleve B. Moler, Computer Methods for Mathematical Computations. Englewood Cliffs, NJ: PrenticeHall, 1977. (See Chapter 5.)
[6] Press, W.H.; Teukolsky, S.A.; Vetterling, W.T.; Flannery, B.P. (2007), ‘Chapter 4. Integration of Functions’, Numerical Recipes: The Art of Scientific Computing (3rd ed.), New York: Cambridge University Press, ISBN 9780521880688
[7] Josef Stoer and Roland Bulirsch, Introduction to Numerical Analysis. New York: SpringerVerlag, 1980. (See Chapter 3.)
Download Details
$4.99
Release Information

Price:
$4.99

Released:
April 30, 2019

Last Updated:
May 28, 2019
Subscribe
Most of the time, we share our discount coupons to our Newsletter Subscribers only. And get products updates also!
Recent Blog Posts
Development of Russian Cars Plat...
154 Views
Reinforcement Learning with MATLAB
157 Views
MATLAB Code For Face Detection
165 Views
LSB Based Image Steganography Us...
398 Views
RGB Image to Grayscale Image Con...
215 Views