1. Composite Gaussian quadrature.
(a) Write a matlab function to implement the composite two-point Gaussian quadrature. The input arguments should include function handle for the integrand
f(x), interval [a, b], and number of subintervals n (or grid spacing h = (b − a)/n
instead). On each subinterval, a two-point Gaussian quadrature rule is used.
Attach your code to the project report.
(b) Code validation. Use your code to compute the integral
and generate data to complete the following table. Here I is the numerical
integral, E = |I − If | where If is the exact integral, and α is the numerical
order of accuracy that can be computed in the same way as problem 2 in project
1. What is the numerical order that you observe? Is it consistent with the
n h I E α
2 1/2 —
(c) How many function evaluations are required in the composite two-point Gaussian quadrature for n subintervals? How many function evaluations are required
if the Simpson’s rule is applied to each of these subintervals? (In the composite
Simpson’s rule, each of these subintervals has 3 nodes with two end nodes shared
with neighbours.) If you need to approximate ∫ b
f(x)dx, where f(x) is discontinuous at x =
, which composite rule (two-point Gaussian or Simpson’s) will
you choose? Why?
(d) The two-point Gaussian quadrature rule can be made adaptive in a way similar to
the adaptive Simpson’s rule. For smooth integrands, which adaptive quadrature
(two-point Gaussian or Simpson’s) is more efficient in terms of the number of
function evaluations? Explain.
2. Consider the following three numerical integration methods: composite two-point
Gaussian quadrature, adaptive Simpson’s rule, and Romberg integration. The code
for the latter two can be obtained from the course web page.
(a) Invent an example (i.e., an integrand f(x), an interval [a, b], and a small tolerance
tol) for which the Romberg integration requires at least five times the function
evaluations of the adaptive Simpson’s rule. For the Romberg integration, you
may try different n until Rn,n satisfies the accuracy requirement. Show the
results from your computations to support your conclusion and plot f(x) on [a, b].
Explain why the adaptive method is more efficient. How does the composite
Gaussian quadrature perform in this case?
(b) Invent an example for which the adaptive Simpson’s rule requires at least five
times the function evaluations of the Romberg integration. Show the results from
your computations to support your conclusion and plot f(x) on [a, b]. Explain
why the Romberg integration is more efficient. How does the composite Gaussian
quadrature perform in this case?
(c) Based on your discoveries in (a) and (b), comment on these methods.
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
2. function [R]=Romberg(f,a,b,n)
%ROMBERG - Romberg integration
% f - function name or function handle
% a,b - integration interval [a,b]
% n - size of the romberg table
% R - an nxn matrix of numerical integrals
% R(i,j): h=(b-a)/2^(i-1), order=2*j
%% Calculate Romberg integration
s=sum(feval(f,a+([1:m]-0.5)*h));%summation at new points
R(i,1)=0.5*(R(i-1,1)+h*s); %composite trapezoidal rule
R(i,j)=R(i,j-1)+(R(i,j-1)-R(i-1,j-1))/(4^(j-1)-1); % extrapolation
%% Output R