Homework/Programming 5. (Due Feb 24.)

advertisement
Homework/Programming 5. (Due Feb 24.)
Math. 417
(MATLAB) For this assignment, you will need to create a matlab routine
which does a composite Simpson’s rule approximation to an integral using
a uniform step size. The interface should look like
function r=simpsons(a,b,N,f)
Here a, b are the limits of integration, N is the number of subintervals, and
f is the integrand.
Problem 1. Apply your composite Simpson’s rule code to approximate
Z 1
dx
.
α
0 (1 + x)
Run your code for N = 10, 20, 40, 80, 160, 320 and α = 1/4, 1/2, 3/4. Report
the error obtained in each case (compared with the answer obtained using
calculus applied to the integral over (0,1)). If your code is working correctly,
you will be able to see the 4’th order global convergence, i.e., when you increase N by two, the error should decrease roughly by a factor of 16.
Problem 2. Apply your composite Simpson’s rule code to approximate the
improper integral
Z 1
dx
.
α
x
0
The simplest way to do this is to skip the first interval (the one containing 0),
i.e., add the contributions from [h, 2h], [2h, 3h], . . ., [(N − 1)h, 1]. Here h =
1/N . Report the errors (compared with the answer obtained using calculus
applied to the integral over (0,1)) for the same values of N and α as above.
The uniform mesh on the improper integral does not do a very good job.
The convergence can be improved by using a non-uniform quadrature node
spacing (discussed in recitation). We shall take a different approach, namely,
we first apply the change of variable x = e−y to obtain
Z ∞
Z 1
dx
=
e(α−1)y dy.
α
0
0 x
We shall use the equally spaced composite approximation to the integral on
the right hand side. The first step is to truncate the interval,
Z M
Z ∞
(α−1)y
e(α−1)y dy,
e
dy ≈
(2.1)
0
0
1
2
and subsequently apply the equally spaced quadrature scheme on the truncated interval (M defined below).
The idea is to try to balance the integral truncation error with the 4’th
order error of the quadrature scheme. The truncation error behaves like
e(α−1)M . To attempt to equalize the number of steps for the same reduction
(independent of α), we set h = ((1 − α)N )−1 with N being our interval
parameter. To equalize the truncation and 4’th order error, we set M by
e(α−1)M = h4 . Solving this, we find that we should take N N steps (of size
h) with N N given by
4 log(h−1 ) = (1 − α)M = (1 − α)h(N N ) = N N/N.
This formula makes sense only when h < 1 (and, of course, N N needs to be
an integer). Thus, we take
N N = ceil(max([4N, 4N log(h−1 )])).
Here the (MATLAB) ceiling function ceil returns the smallest integer which
is greater than or equal to the given floating point number.
Problem 3. Run α = 1/4, 1/2, 3/4 but use N = 4, 8, 16, 32, 64 with N N
steps of size h to approximate the integral on the right hand side of (2.1).
The above scheme increases the number of intervals only logarithmically but
asymptotically recovers 4’th order convergence. Again report the error (comparing with the calculus result for the integral on (0,1) of Problem 2) and
N N for each combination of N and α.
Problem 4. (By Hand) Do #2 and #4, P202.
Problem 5. (By Hand) Compute the coefficients which makes the scheme,
Z 2
f (x) dx ≈ c0 f (−1) + c1 f (0) + c2 f (1),
−2
exact for quadratics by two methods, undetermined coefficients and integration of the Lagrange polynomials. Find the largest integer k for which the
scheme is exact on Pk . Show that it is not exact on Pk+1 . Show all of your
work.
Hand in the results for the above problems and a copy of any
matlab code that you created to do the assignment.
Download