Numerical Integra/on
The Trapezoidal Rule is a technique to approximate the definite integral where For 1 st order: f(a) f(b) a b
Error Es/mate of Trapezoidal Rule Truncation error: From Newton-Gregory formula (interpolation with equally spaced data) where h = step size between data points
Error Es/mate of Trapezoidal Rule take the first order with error term and integrate Since the limits of integration: Then
Error Es/mate of Trapezoidal Rule For small h, it is assumed that the term approximately constant, then is
Example Use the trapezoidal rule to numerically integrate f(x) =0.2+2x + 90x 2 120x 3 + 25x 4 from a = 0 to b = 0.8.
Example Use the trapezoidal rule to numerically integrate f(x) =0.2+2x + 90x 2 120x 3 + 25x 4 from a = 0 to b = 0.8. Solution: The function values f(0) = 0.2 f(0.8) = 8.2 Can be substituted into the trapezoidal rule equation to get I =0.8 0.2+8.2 2 =3.36
Example The exact value of the integral is 5.5104, and the error is E t =5.5104 3.36 = 2.1504 which corresponds to a percent relative error of 39%.
Mul/ple- Applica/on Trapezoidal Rule Improving the accuracy of the trapezoidal rule is by dividing the integration interval from a to b into a number of segments and apply the method to each segment. Dividing the interval into equally spaced base points (x 0, x 1, x 2,, x n ), gives n segments of equal width h, where: The total integral: Substituting the trapezoidal rule for each interval yields:
Mul/ple- Applica/on Trapezoidal Rule Or in general form and the error is second derivative at point located at segment i
MATLAB Implementa/on Use Matlab s built-in function trapz to estimate the integral of the following equation using 5 segment trapezoidal rule f(x) =0.2+2x + 90x 2 120x 3 + 25x 4 from a = 0 to b = 0.8. Recall that the exact value of the integral is 5.5104.
MATLAB Implementa/on % Create a vector with 5 equal segments from 0 to 0.8 x = linspace(0, 0.8, 6); % Calculate the function y y = 0.2 + 2*x + 90*x.^2 120*x.^3 + 25*x.^4; % Use trapz to integrate the data points q = trapz(x,y); Running the code gives q = 5.4349. Hence the relative error with respect to the exact value is
MATLAB Implementa/on Now, create your own solver using Matlab to estimate the integral of the following equation with 5 segment trapezoidal rule f(x) =0.2+2x + 90x 2 120x 3 + 25x 4 from a = 0 to b = 0.8. Recall that the exact value of the integral is 5.5104.
MATLAB Implementa/on % Number of segments n = 5; % Integral limits lowerlimit = 0; upperlimit = 0.8; % Discretization into equally spaced segments x = linspace(lowerlimit,upperlimit,n+1); % Define function to integrate y = 0.2 + 2*x + 90*x.^2-120*x.^3 + 25*x.^4; % Trapezoidal formula A = sum(y(2:n)); M = 2*A; I = (upperlimit-lowerlimit)*(y(1)+m+y(end))/(2*n); disp(['estimation of the integral is ', num2str(i)]);
MATLAB Implementa/on Now, create your own solver using Matlab to estimate the integral of the following equation with 5 segment trapezoidal rule f(x) =0.2+2x + 90x 2 120x 3 + 25x 4 from a = 0 to b = 0.8. You must not use SUM built-in function, but create a syntax that mimics the sum function. Recall that the exact value of the integral is 5.5104.
MATLAB Implementa/on % Number of segments n = 5; % Integral limits lowerlimit = 0; upperlimit = 0.8; % Discretization into equally spaced segments x = linspace(lowerlimit,upperlimit,n+1); % Define function to integrate y = 0.2 + 2*x + 90*x.^2-120*x.^3 + 25*x.^4; % Trapezoidal formula A = 0; for i=2:n A = A + y(i); end M = 2*A; I = (upperlimit-lowerlimit)*(y(1)+m+y(end))/(2*n);
Simpson s 1/3 Rule uses second-order interpolating polynomial to approximate definite integrals where f 2 (x) is represented by a second-order Lagrange polynomial, hence a is designated as x 0 and b as x 2.
Or in compact form Simpson s 1/3 Rule and the truncation error where
Mul/ple- Applica/on Simpson s 1/3 Rule Simpson s 1/3 rule can be improved by dividing the integration interval into a number of segments of equal width: The total integral can be represented as: and the error: is as in previous slide
Simpson s 3/8 Rule uses a third-order Lagrange interpolating polynomial to approximate definite integrals. The total integral is expressed as and the error is as in previous slide.
Example Consider the function over the fixed interval Apply the various quadrature formulas to approximate integral of the function.
Example Consider the function over the fixed interval Apply the various quadrature formulas to approximate integral of the function. From substitution of the integral limits into f (x): For the trapezoidal rule,
For Simpson s 1/3 rule, Example For Simpson s 3/8 rule, For multiple application formulas, divide the integral limits into equally spaced points, such as, if n = 5, then
Example If we chose, then and the equally spaced points and their corresponding function values are For the multiple-application trapezoidal rule:
Example For the multiple-application Simpson s 1/3 rule:
Example To compute error estimate for the trapezoidal rule, the function s second derivative over the interval can be computed by differentiating the original functions twice to give: The average value of the second derivative: Use integration by parts to evaluate (see Improper Integrals)
Integra/on with Unequal Segments By applying the trapezoidal rule to each segment, the total integral for problems with unequal step sizes or segments is given by: where h i is the width of segment i.
Example Estimate the integral of spaced points with unequally and
Example Estimate the integral of spaced points with unequally and The exact value of the integration is 3.3333. The function values at each point are
Example Using the formula for integration with unequal segments: which represent an absolute relative error of
Romberg Integra/on This method uses Richardson extrapolation to approximate the definite integral Starting with the multiple application trapezoidal rule For estimates with halving the step size:
Romberg Integra/on To improve the estimates with higher accuracy, if the step size h is further halved
Example Use Romberg integration based on Richardson extrapolation to estimate the integral of with integration limits from a = 0 to b = 0.8.
Example Use Romberg integration based on Richardson extrapolation to estimate the integral of with integration limits from a = 0 to b = 0.8. (The exact value of the integral is For integration limits a = 0 and b = 0.8, the segment h is 0.8: Halving the segment, now we have:
Example The total integral: Relative error:
Adap/ve Quadrature is used for unequally spaced points: where
And the error Adap/ve Quadrature
is given by Gauss Quadrature The truncation error The weights a i are given by where the abscissas x i are the n zeros of the Legendre polynomial P n
Gauss Quadrature Legendre polynomials P n (x) is given by
Improper Integrals Given an improper integral or an integral with a nonregular integrand, such as with unbounded derivatives. Before using some numerical method (e.g., Simpson s formula), the integral may be transformed by substitution, integration by parts or series expansion, etc. Example: the substitution x = t 2 transforms the integrals to the regular forms
References Numerical Methods for Engineers, S.C. Chapra and R.P. Canale.