Numerical Integration: Riemann Sums, the Midpoint Rule, and the Trapezoidal Method
Foundations of Definite Integrals and Numerical Approximation
Partitioning the Integration Interval:
- An interval on the -axis is partitioned into subintervals defined by discrete points: .
- Subintervals are assumed to be equidistant, with a uniform width defined by .
- Depending on the convention used, indexing may begin at through , or from to . Regardless of indexing notation, the core mechanics of calculation remain invariant.
The Definite Integral as a Limit of a Riemann Sum:
- The standard mathematical definition of the definite integral involves taking the limit as the number of subintervals (rectangles) approaches infinity:
- Inside the integral symbol, the integrand function and the differential element directly mirror the terms and inside the summation.
Reformulation in Terms of a Width Parameter Approaching Zero:
- Conceptually, computing limits where a parameter approaches infinity () can be non-intuitive to model numerically on computational hardware.
- Paralleling the definition of the derivative, where , the definite integral can be restructured so that the partition step size approaches zero rather than the count .
- In numerical computation, a limit where can be practically interpreted through machine epsilon (), which represents the smallest positive number that can be stored in floating-point memory such that .
- Letting represent the machine epsilon gives a fundamental theoretical boundary for the finest possible approximation step size on a digital machine (subject to the scale/magnitude of the problem).
- Given an interval and a uniform step size , the total number of subintervals is:
- The definite integral can therefore be equivalently expressed as:
Newton's Conceptualization of Calculus:
- Calculus was formulated by Isaac Newton as an analytical language to describe physical realities that were already known to exist, such as continuous motion in physics.
- Newton conceptualized geometric and physical quantities not by beginning with an abstract absolute formula, but by constructing an approximation and then driving it to convergence through a limit.
- The Derivative: The tangent line is initially approximated by a secant line passing through two points; as the points move arbitrarily close, the secant line converges to the tangent line.
- The Integral: The area under a curve is initially modeled by approximating geometric shapes (rectangles); as the widths of these shapes shrink to zero, the sum of their areas converges to the exact area under the curve.
- In modern abstract mathematics, approximations are typically derived downwards from abstract principles, whereas foundational calculus developed abstract mathematical structures upward from physical approximations.
Analytical Evaluation of the Test Function
Test Function and Objective:
- The primary function evaluated across various numerical quadrature schemes is:
- The domain of integration is chosen over the closed interval .
- The function is deliberately shifted vertically upward by to ensure that the curve remains strictly above the -axis across the entire interval, thereby providing a non-zero height and positive area beneath the curve for the very first partition.
Antiderivative and Exact Definite Integral:
- The general indefinite integral (antiderivative) is: where is an arbitrary constant of integration.
- Differentiating this confirms the integrand:
- Evaluating the definite integral from to using the Fundamental Theorem of Calculus:
- The constants of integration cancel out algebraically:
- The exact analytical area under the curve is .
Rectangle-Based Riemann Sum Formulations
Discretization Parameters:
- Interval: partitioned into equal subintervals (rectangles).
- Number of boundary points: points, labeled , where and .
- Uniform width of each rectangle: .
- Coordinates of partition points: , for .
The Choice of Height ():
- The primary implementation question for rectangular numerical integration is determining which -coordinate within each subinterval evaluates the height of the rectangle.
- The three standard selections are:
- Left Endpoint: Evaluated at the start of each subinterval: .
- Right Endpoint: Evaluated at the end of each subinterval: .
- Midpoint: Evaluated at the arithmetic mean of the boundary points: .
Summation Formulas:
- Left Endpoint Approximation ():
- Right Endpoint Approximation ():
- Midpoint Approximation ():
Left and Right Endpoint Numerical Computations
Left Endpoint Rule Calculations on over :
- Rectangle:
- Width: .
- Height: .
- .
- Result: Significantly underestimates the true value of .
- Rectangles:
- Width: .
- Subintervals: and .
- Heights: , .
- .
- Rectangles:
- Width: .
- Subintervals: , , , and .
- Heights and individual rectangle areas:
- Rectangle 1: Height , .
- Rectangle 2: Height , .
- Rectangle 3: Height , .
- Rectangle 4: Height , .
- Total Sum: .
- Rectangles:
- Width: .
- Evaluates previously calculated heights plus newly sampled quarter-increment coordinates: .
- All values are factored by the width (or divided by ).
- Convergence Behavior: Even scaling up to rectangles does not comfortably yield reliable single decimal place precision (fails to reach ). For algorithms requiring rectangles, computing simple rectangular endpoints demands an enormous number of arithmetic operations while remaining inefficient.
- Rectangle:
Right Endpoint Rule Calculations on over :
- Rectangle:
- Width: .
- Height: .
- .
- Result: Significantly overshoots the true value of .
- Rectangles:
- Width: .
- Heights: , .
- .
- Rectangles:
- Width: .
- Heights: , , , .
- .
- Error Comparison: is off from the analytical value () by approximately , roughly symmetric in magnitude of error to the left endpoint value (, off by ).
- Rectangles:
- Result: Yields .
- Rectangle:
The Midpoint Rule and Error Cancellation Mechanics
Geometric Mechanism of the Midpoint Rule:
- Instead of evaluating the height at either boundary of a subinterval, the midpoint rule samples the function at the center: .
- On any subinterval where the function is strictly increasing:
- Across the left half of the rectangle, the horizontal rectangular top sits above the actual function curve (local overestimation).
- Across the right half of the rectangle, the horizontal rectangular top sits below the actual function curve (local underestimation).
- Because one half of the subinterval overestimates while the other half underestimates, the two error areas geometrically cancel each other out to a substantial degree.
- Similarly, if a function is strictly decreasing over a subinterval, the left half underestimates and the right half overestimates, achieving the same self-canceling error behavior.
Midpoint Rule Numerical Calculations on over :
- Rectangle:
- Width: .
- Midpoint: .
- Height: .
- .
- Comparison: An area of is notably closer to than the left endpoint result () or right endpoint result ().
- Rectangles:
- Width: .
- Subintervals: and .
- Midpoints: , .
- Heights: , .
- .
- Comparison: With just rectangles, the midpoint rule () achieves a far superior approximation to the analytical value () than either the left () or right () endpoint methods achieved with rectangles.
- Rectangles:
- Width: .
- Midpoints: .
- .
- Comparison: Successfully captures the first decimal digit ().
- Rectangles:
- Width: .
- Midpoints: Values across the interval from to expressed in eighths that do not simplify to fourths:
- Evaluating at these eight midpoints and scaling by yields a value exceptionally close to .
- Rectangle:
Monotonicity and Edge Cases:
- The error cancellation of the midpoint rule is sustained when a function is monotonic (consistently increasing or decreasing) over each subinterval.
- Potential edge cases arise if a function exhibits an internal local extremum within a single rectangle (e.g., increasing up to a peak and then decreasing). However, as the step size decreases, the width of individual rectangles becomes sufficiently small that local turning points occupy an increasingly negligible fraction of the total partition.
The Trapezoidal Rule: Derivation and Mechanics
Algorithmic Critique of Constant Approximations:
- Left and right endpoint methods approximate the curve on each subinterval using a constant function (a degree-0 polynomial, represented by a flat horizontal line):
- Approximating an arbitrary curve with a constant function fails to model the actual mathematical behavior of the function. Constant approximations are only exact when integrating a flat line (such as ).
- For a strictly increasing function, a flat left-aligned box must systematically underestimate every subinterval, and a right-aligned box must systematically overestimate every subinterval.
Linear Modeling via Secant Lines:
- Rather than a constant line, the function over is better approximated by a secant line connecting the boundary coordinates and .
- As established in Taylor polynomial theory and differential calculus, secant lines approach the tangent line as the width decreases, capturing both the local value and the rate of change of the function.
- Geometrically, the region beneath a slanted secant line between and forms a trapezoid.
Mathematical Derivation of the Trapezoid Area:
- A trapezoid is half of a rectangle whose height is the sum of the two parallel vertical bases and whose width is the base width :
- When summing across consecutive subintervals, every internal boundary wall is shared by two adjacent trapezoids (acting as the right edge of trapezoid and the left edge of trapezoid ).
- Consequently, each internal evaluation for appears twice in the sum, whereas the exterior endpoints and appear only once:
Trapezoidal Numerical Calculations on over :
- Trapezoid:
- Width: .
- Boundary heights: , .
- .
- Comparison: While it overshoots the true answer (), an area of is vastly superior to the single right-rectangle result of .
- Trapezoids:
- Width: .
- Points: , , .
- Heights: , , .
- Trapezoid 1 Area (over ): .
- Trapezoid 2 Area (over ): .
- Total Area: .
- Error: The error is exactly .
- Trapezoids:
- Width: .
- Evaluating across the points gives approximately (or zoomed detail displaying ).
- Trapezoid:
Comparative Synthesis of Quadrature Methods
Summary Table for on (Exact Value = ):
Single Region ():
- Left Endpoint:
- Right Endpoint:
- Midpoint Rule:
- Trapezoidal Rule:
Two Regions ():
- Left Endpoint:
- Right Endpoint:
- Midpoint Rule:
- Trapezoidal Rule:
Theoretical Comparison: Midpoint vs. Trapezoid:
- Accuracy in the Test Problem: For the convex curve , the midpoint method numbers ( for ) are numerically closer to than the trapezoid method numbers ( for ).
- Underlying Rationales: The midpoint rule benefits from internal geometric cancellation where under-approximations and over-approximations offset each other across each rectangle. By contrast, because is strictly concave up (), the secant line sits entirely above the curve, causing the trapezoidal rule to consistently overestimate across all subintervals.
- Practical Application: The midpoint rule on average performs remarkably well, but specific functions can be engineered where midpoint cancellation breaks down. The trapezoidal rule directly models the dynamic slope of the function on every interval via secant lines. Because their computational performance is within a comparable order of magnitude, both provide solid numerical approximations.
Computational Implementation in GraphState
GraphState Software Syntax:
int(f, [a, b]): Standard syntax to define and plot a definite integral of functionfacross the interval[a, b].rn = [count]: Parameter defining the Riemann sum subdivision. For instance, settingrn = 5renders five discrete rectangles evaluated via the midpoint rule.- To plot the continuous, true definite integral without rectangle discretization, the
rnmetric is omitted.
Laboratory Assignment Tasks:
- Target function: starting from .
- Task 1: Approximate with regions using the Midpoint rule.
- Task 2: Approximate with regions using the Trapezoidal rule.
- Task 3: Compute the exact analytical solution using the fundamental antiderivative of the sine function:
Questions & Discussion
Audience Question / Discussion on Limits and Machine Representation:
- Question/Prompt: How can one conceptualize or compute a limit approaching infinity when finite machines cannot evaluate out to infinity?
- Response: Limits to infinity can be algebraically restructured into limits where a parameter approaches zero (). In computational terms, the limit as is interpreted via machine epsilon—the smallest increment storeable where . Setting to this fundamental threshold represents the highest precision approximation attainable on a digital system for that scale.
Audience Question / Discussion on Algorithmic Inefficiency of Endpoint Rules:
- Question/Prompt: Why are left and right endpoint approximations fundamentally inefficient processes for calculating areas under curves?
- Response: Endpoint algorithms model the function using a constant function (flat horizontal top) over each subinterval. For an increasing function, every single right box overestimates and every left box underestimates. Because constant functions ignore the slope and behavior of non-constant functions entirely, thousands or millions of rectangles are required to attain modest precision.
Audience Question / Discussion on Midpoint Accuracy versus Trapezoidal Validity:
- Question/Prompt: Why would one consider using the trapezoidal method if the midpoint method produced numbers closer to the exact answer ( vs. for )? Is midpoint accuracy merely an artifact of errors canceling out rather than true curve tracking?
- Response: The midpoint rule is on average exceptionally accurate because internal errors offset. However, functions can be constructed (e.g., oscillating trigonometric functions like over selected intervals) where midpoint cancellation does not perform as reliably. The trapezoid method explicitly incorporates the secant line to track function slopes; both methods are closely aligned in utility, and testing across varying intervals confirms their respective strengths.
Audience Question / Discussion on GraphState Technical Troubleshooting:
- Question/Prompt: When pasting the definite integral command into GraphState, a plot fails to appear and returns a line error. What is causing this failure, and does a sine symbol need to be removed?
- Response: The error is not an issue with duplicate sine syntax, but rather a browser caching bug. When GraphState encounters an error on an initial parse, it caches that parsed state in memory so it does not redundantly re-parse identical input. As a result, updating the input field without refreshing leaves the error active.
- Resolution Procedure: While a standard hard refresh is typically executed via
Ctrl + Shift + R, the commandAlt + Shift + Rforces GraphState internally to clear its cached parsing tree and completely re-parse the command from scratch, resolving the line error.