Exercise 2
Exercise 2
DEPARTMENT OF MATHEMATICS
Math 603: Numerical Methods of DE
Exercise 2
1. We want to implement the central differences discretization of the following boundary value problem:
(a) Letting f = sin(πx), α = β = 0 and M = 9, construct the linear Ah U~ = F~ and solve it with Matlab’s
backslash command to find the numerical solution U ~ . Plot the numerical solution. Find the exact
solution of the boundary value problem by integrating twice. Plot the values of the solution on the
grid and compare them to the corresponding numerical approximation values. Run the program with
different values of M and observe the behaviour of the numerical method. Then choose another f
leading to non-trivial boundary values and repeat the exercise.
(b) Use the values of the exact solution on the grid points to compute the error vector ~eh := [U1 −
u1 , . . . , UM − uM ]T , where um = u(xm ). Consider then the piecewise constant error function defined by
We know from Taylor’s theorem that the exact solution can be expanded as
1 00 h2 (4)
(uj+m − 2um + um−1 ) = u (x m ) + u (xm ) + O(h4 ).
h2 12
It can also be proved that eh (x) goes to zero in 2-norm (for functions) as O(h2 ). We design our
numerical experiment as follows: consider increasing values of M, for example M = 2k , k = 1, 2, . . . , 8
and decreasing values of h accordingly. Solve the linear system from tasks (a) for each value of M and
compute the corresponding norm of the error in max-norm, 1-norm and 2-norm. Store the obtained
values. Now plot in logarithmic scale the different values of h versus the corresponding values of the
error norm for the three different choices of norm. You should observe a straight line with slope 2,
corresponding to second order convergence.
1
(c) Now modify your program to implement Neumann BCs, i.e. consider the problem
uxx (x) = f (x), 0 < x < 1, u0 (0) = σ, u(1) = β.
There are several strategies discussed in the lecture of the course: CASE 1 is a first order method,
CASE 2 is a second order method using fictitious nodes, CASE 3 is a second order method leading to a
matrix which is not tridiagonal but without using fictitious nodes. Implement each of these and verify
the order of each technique numerically. Hand-in: Plot (in logarithmic scale) of h versus the 2-norm for
the three cases.
2. Given the two point boundary value problem:
uxx − 2ux + u = 0, 0 ≤ x ≤ 1, u(0) = 2, ux (1) = 0
The exact solution is
u(x) = (2 − x)ex .
(a) Set up a finite difference scheme for this problem, using central differences. For the right hand boundary,
use the idea of a fictitious boundary and central differences. Use ∆x = 1/(M + 1) as the grid size, and
let xm = m∆x, m = 0, 1, . . . M + 1.
(b) Let M = 2 and use the above formula to find approximations Um ≈ u(xm ), m = 1, 2. (i.e. Set up the
system of equations, and solve it by hand). Compare with the exact solution.
(c) Modify the code of BVP in problem (1) and solve the problem numerically. Use M = 9, 19, 39 in your
simulation. For each M , write down the error
e(h) = max |u(xm ) − Um |
0≤m≤M +1
What can you deduce about the order of the scheme from this experiment?
(d) Repeat point (a) and (c), but this time by using a backward difference (and no false boundary) to
approximate the boundary condition ux (1) = 0. Compare the error and the order of the scheme with
your previous results.
(e) Assume that the right boundary condition is changed to
ux + u = 0 at x = 1.
What will the difference equation in the boundary point x = 1 be in this case?
3. Set up the Euler’s method to approximate and plot the solution of the heat equation ut = uxx on the interval
[0, 1] with boundary condition g0 (t) = g1 (t) = 0 and initial condition
2
(a) u(x, 0) = sin(πx). The exact solution of the problem is u(x, t) = e−π t sin(πx).
(
2x, 0 ≤ x ≤ 0.5,
(b) u(x, 0) = .
2(1 − x) 0.5 < x ≤ 1