2025 Week 7-2 - Numerical differentiation and integration
Overview
The lecture develops finite-difference differentiation and numerical integration by deriving formulas from Taylor expansions, comparing their error orders, and discussing how data spacing, boundaries, and noise affect accuracy. It progresses from Newton-Cotes rules, including trapezoid and Simpson's 1/3 rule, to Richardson extrapolation and Romberg integration, then derives two-point Gaussian quadrature and connects its sampling points to finite element methods.
Key takeaways
- Central difference achieves O(h²) accuracy by canceling leading Taylor terms, while forward and backward difference are O(h); endpoint calculations need second-order one-sided formulas to preserve that accuracy.
- Differentiation amplifies high-frequency measurement noise, so noisy velocity data can produce unusable acceleration estimates; filtering, regularization, or local polynomial fitting can mitigate the problem.
- For fixed integration limits, summing local errors changes the global convergence order: trapezoid has local O(h³) error and global O(h²), while Simpson's 1/3 rule reaches global O(h⁴) on evenly spaced data.
- Richardson extrapolation combines trapezoid estimates at step sizes h and h/2 to cancel the leading O(h²) error, and repeated corrections form Romberg integration.
- Two-point Gauss-Legendre quadrature evaluates a function at ±1/√3 on [-1, 1] and exactly integrates polynomials through degree three, giving high accuracy with only two function calls.
- Sampling assumptions determine method choice: trapezoid handles unevenly spaced tabulated data, whereas standard Simpson and Romberg procedures depend on structured spacing.
Chapters
- Forward, backward, and central difference formulas approximate derivatives using function values at points separated by step size h.
- Taylor expansions provide the algebra for isolating the derivative and identifying the terms that cause truncation error.
- Method accuracy is assessed by how its error changes as h decreases.
- Forward difference uses [f(x+h) - f(x)]/h, while backward difference uses [f(x) - f(x-h)]/h.
- Subtracting the forward and backward Taylor expansions cancels even powers of h and yields [f(x+h) - f(x-h)]/(2h).
- Central difference is second-order accurate, compared with first-order forward and backward differences, without requiring more than two function evaluations.
- Central difference requires data on both sides of x, so it cannot be applied directly at the endpoints of a data interval.
- Using first-order forward or backward formulas at the boundaries can reduce the accuracy of an otherwise second-order calculation.
- A three-point one-sided formula derived from Taylor expansions provides second-order boundary accuracy and avoids that loss.
- A three-point forward difference can improve boundary accuracy to O(h²), matching central difference's order.
- A higher-order central-difference formula can reach O(h⁴), but typically requires four function evaluations.
- Reducing h is often the first practical refinement, but these formulas rely on regular spacing and can be unsuitable for uneven meshes.
- For higher-dimensional data, approximate each component of the gradient along its corresponding grid direction.
- Multidimensional grids introduce boundaries and corners, where one-sided formulas or other boundary treatments are needed.
- Regularly spaced meshes make standard finite-difference formulas straightforward to apply.
- The example differentiates discretized data shaped like a parabola, whose true derivative should be a straight line.
- NumPy's gradient uses central differences in the interior and one-sided differences at the endpoints.
- Setting edge_order=2 applies second-order endpoint formulas and makes the computed derivative align with the expected line.
- Forward and backward differences can use a single unequal step because each formula only needs one neighboring interval.
- Standard central and higher-order formulas assume equally spaced points, so their Taylor-expansion cancellations do not generally hold on uneven data.
- For several points, fit a local interpolating polynomial, such as a Lagrange polynomial, and differentiate it rather than fitting one high-degree polynomial to all the data.
- Small fluctuations in measured rocket velocity can become large oscillations in the calculated acceleration because differentiation emphasizes high-frequency components.
- Possible remedies include low-pass filtering, moving averages, Tikhonov regularization, and Savitzky-Golay local polynomial fitting.
- Integration often suppresses high-frequency noise by accumulating and partially canceling fluctuations.
- A definite integral represents the area under a curve between specified limits and can be computed from a callable function or tabulated x-y data.
- Unlike differentiation, integration tends to damp experimental noise through accumulation.
- The lecture introduces numerical integration approaches for both function evaluations and measured data.
- For two intersecting circles, solving a nonlinear system means finding their geometric intersection points; the example has two roots.
- Newton-Raphson uses the Jacobian and a linear solve, and the circle example's 2-by-2 Jacobian is dense.
- The assignment review contrasts one-dimensional Brent optimization with gradient-based methods, which suit higher-dimensional problems and can locate saddle points.
- Newton-Cotes methods divide an interval into subdomains, fit low-degree polynomials, integrate those polynomials, and sum the results.
- Local calculations can be performed independently, making the method amenable to parallel computation.
- The global error depends on both the error on each subinterval and the number of subintervals.
- Left- and right-endpoint Riemann sums use degree-zero, constant approximations on each subinterval.
- For a smooth function, the local error is O(h²), while summing across the full domain gives global error O(h).
- The lecture distinguishes integrating a callable function from integrating experimental data available only at sampled points.
- The midpoint rule samples the function at each subinterval's center and has global error O(h²).
- Tabulated data often lack midpoint values, limiting direct use of the midpoint rule unless the function can be evaluated there.
- The trapezoid rule connects adjacent data points and also has global error O(h²), making it a practical choice for unevenly spaced data.
- Simpson's 1/3 rule fits a quadratic across pairs of intervals and achieves global error O(h⁴) on equally spaced data.
- Its symmetry cancels a higher-order Taylor term, so its accuracy improves faster than the trapezoid rule's as h decreases.
- When the number of intervals does not form pairs, Simpson's 3/8 rule fits a cubic over three intervals; the lecture also notes that Simpson's methods require regular spacing.
- The recap identifies trapezoid integration as a reliable fallback for uneven data and Simpson's rules as options for evenly spaced data.
- Romberg integration repeatedly applies the trapezoid rule at successively smaller step sizes.
- Richardson extrapolation compares approximations at different h values to estimate and cancel leading error terms.
- The trapezoid rule's global error begins at O(h²), allowing estimates from two step sizes to be combined.
- Using step sizes in a 2-to-1 ratio makes the leading O(h²) term cancel, producing an O(h⁴) estimate.
- The combination can improve an integral computed from existing equally spaced data without requiring new measurements.
- Romberg integration repeats Richardson-style corrections across progressively finer, commonly halved, step sizes.
- Previously computed function values can be reused, and the recurrence lends itself to compact recursive implementations.
- SciPy includes a Romberg implementation, which the lecture recommends using rather than memorizing the general formula.
- Romberg extrapolation works best when the function's curvature changes smoothly across the sampled interval.
- Rapid oscillations or noisy data can undermine the assumption that error terms at different step sizes are comparable.
- For sin(x) integrated from 0 to π, Romberg error falls rapidly, but apparent errors near 10⁻¹⁶ reach double-precision roundoff rather than proving exact arithmetic.
- Newton-Cotes and Romberg rules use prescribed sampling points and combine function values with weights.
- Gaussian quadrature chooses both the sample locations and weights to make the integration formula exact for polynomials up to a specified degree.
- The method requires function evaluations at its chosen points, or a computational framework designed to supply values there.
- On the reference interval [-1, 1], the two-point Gauss-Legendre rule uses nodes -1/√3 and 1/√3, each with weight 1.
- Matching the integral for the monomials 1, x, x², and x³ determines the four unknowns: two nodes and two weights.
- The resulting formula exactly integrates every polynomial of degree three or lower using only two function evaluations.
- Gaussian quadrature is derived on [-1, 1], so an arbitrary interval must be transformed to that reference domain.
- The coordinate transformation also scales the integral by the mapping's interval-length factor.
- Using more Gauss points integrates higher-degree polynomials exactly, with two points providing fourth-order accuracy for smooth functions.
- Repeated integration extends quadrature to multiple dimensions, but mapping irregular elements to a reference shape requires additional transformations.
- Finite element methods use element mappings to evaluate functions at Gaussian points within each mesh element.
- Quadrilateral elements can become degenerate as an edge shrinks, while triangles are common mesh elements for two-dimensional domains.
- Finite element formulations select Gaussian points and weights to integrate over mapped elements.
- The lecture relates the number of Gauss points to integration accuracy and describes how point placement can affect continuity between elements.
- Detailed element transformations and tensor calculations are identified as topics for dedicated finite element courses.
- Newton-Cotes rules are practical for tabulated data, with the trapezoid rule available when spacing is uneven.
- Simpson's rules and Romberg integration benefit from structured, evenly spaced samples, while Gaussian quadrature is attractive when function calls are expensive.
- A two-point Gaussian rule can provide fourth-order accuracy with only two evaluations, a useful tradeoff when evaluating a finite element model is costly.
- The trapezoid rule has local error O(h³) on each subinterval.
- An interval of fixed length contains a number of subintervals proportional to 1/h, so summing local errors yields global error O(h²).
- The worked explanation connects step size, interval count, and overall convergence.
Transcript excerpt
0:02 I'm joking. I'm joking. Just joking. Okay. Uh numerical differentiation. So this is this section will not be on the midterm, right? The midterm is only up to an including optimization. This is kind of the the second part of everything uh where things actually start to get really interesting. So differentiation, what you guys are going to be getting sick of by the end of the next two weeks is Taylor series and basic algebra. To be entirely honest, the name of the game is going to be doing tailaylor expansion, right? Taylor is all about differentiation. What we're going to be doing is rearranging that to isolate the terms that we're interested in. And then we're going to apply some tricks to cancel out the ones that we're not. And we're going to try and cancel out some of those higher derivatives. Okay. So, we've already kind of started on the idea of differentiation of forward differentiation through the
0:49 secant method, right? This is one of the methods for uh for optimiz excuse me for root finding. We started with two points P and Q. We said the line that connects it is called your secant, right? Your secant connects is the chord that connects two points on a curve. As Q approaches P, you achieve the tangent, right? Basic uh basic calculus. I guess that would be first year at this point. Yeah. Um blah blah blah blah blah. So most of these methods, if not all of them, are going to be characterized by your step size. Okay. And your step size is going to be the difference between these two points P and Q. Um, not surprisingly, what we're going to be doing is looking at the order of convergence, excuse me, how does your
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Numerical Methods for Engineering.