0% found this document useful (0 votes)
6 views

Exercise 2

This document contains instructions for numerical exercises involving the discretization and solution of partial differential equations using finite difference methods. It includes: 1) Implementing central difference discretization of a boundary value problem and examining convergence as the grid is refined. 2) Setting up finite difference schemes for two-point boundary value problems and examining errors. 3) Implementing Euler's method and analyzing accuracy for heat equations with different boundary and initial conditions. 4) Approximating the solution of a heat equation using implicit Euler and Crank-Nicolson and examining errors.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Exercise 2

This document contains instructions for numerical exercises involving the discretization and solution of partial differential equations using finite difference methods. It includes: 1) Implementing central difference discretization of a boundary value problem and examining convergence as the grid is refined. 2) Setting up finite difference schemes for two-point boundary value problems and examining errors. 3) Implementing Euler's method and analyzing accuracy for heat equations with different boundary and initial conditions. 4) Approximating the solution of a heat equation using implicit Euler and Crank-Nicolson and examining errors.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ARBA MINCH UNIVERSITY

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:

u00 (x) = f (x), 0 < x < 1, u(0) = α, u(1) = β.

Considering the grid of equidistant points


1
xm = m · h, m = 0, 1, . . . , M + 1, h= .
M +1
On each node xm we replace the second derivative in the differential equation with its approximation by
central differences and get
1
(Um−1 − 2Um + Um+1 ) = fm , m = 1, . . . , M.
h2
Using the boundary conditions U0 = α, UM +1 = β we get a system of M equations in the M unknowns
~ = [U1 , . . . , UM ]T , F~ = [f1 − α2 , f2 , . . . , fM −1 , fM − β2 ]T and
~ = F~ where U
U1 , . . . , UM that is Ah U h h
 
−2 1 0
 .. 
 1 −2 1
 .

1  .. .. .. 
Ah := 2  0 . . . 0
h  
 . .
.. .. .. 

 . 1

0 1 −2

(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

e(x) := em , x ∈ [xm , xm+1 ), m = 1, . . . , M.

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

• By choosing M = 3 (i.e. h = 14 or x0 = 0, x1 = 0.25, x2 = 0.5, x3 = 0.75, x4 = 1) find Ui1 ≈ U (xi , t1 =


k), i = 0, 1, 2, 3, 4 for ∆t = k = 0.025 by hand for (a) and (b). Show that the stability condition is
satisfied for this values of h and k.
• Implement the Forward Euler method, the Backward Euler method and the Crank-Nicholson method
for the heat equation. Verify with numerical experiments the order in time and space for each of the
implemented techniques. Compare the numerical solution with the exact solution.
• Consider now a heat equation problem with Neumann boundary conditions. Implement these boundary
conditions using different strategies (order 1 and 2, with and without fictitious nodes) and verify the
order for each strategy.

4. Approximate the solution of the equation


2 2
ut = uxx , u(0, t) = e−π t , u(1, t) = −e−π t , u(x, 0) = cos(πx),
up to tend = 0.2 by implicit Euler and Crank-Nicolson by implementing it in MATLAB. Plot the solution
2
and the error. The exact solution is u(x, t) = e−π t cos(πx).
Use N = M, and M = 10 and M = 100 (for example). Notice that there are no stability issues, even for r
large. Also notice the difference in accuracy for the two methods.

You might also like