
Math 574
Midterm # 2: due April 19
Problem 1. Consider finite difference method to solve the Laplace prob- lem
and
−uxx − uyy = sin(πx) sin(πy) in Ω = (0, 1)2,
u = 0 on the boundary ∂Ω.
Let (xi, yj )0≤i,j≤N be uniform grids discretize the domain Ω and Let Uij de- note the approximation of u at point (xi, yj ) and Fij = f (xi, yj ).
a) Write down the finite difference method for solving the Laplace equation above.
b) In MATLAB implementation, we use the command
U = zeros(N+1, N+1);

to generate an initial guess of (U 0 )0≤i,j≤N to approximate u(xi, yj ). To solve for Uij satisfies part a), write down a Gauss-Seidel iteration to generate a

(k)
ij
c) In MATLAB code, we use the command
f = @(x,y) sin(pi*x).*sin(pi*y);
to define the function f (x, y) = sin(πx) sin(πy) and use the command
[X,Y] = meshgrid(0:h:1); F = f(X,Y);to generate Fij = f (xi, yj ). Implement the Gauss Seidel iteration in part b). Set the tolerance tol = 1e-9, and
err = max
(k) (k−1)

ij ij
1≤i,j≤N −1
stop the iteration if err < tol. To plot the approximation U , use the com- mand
surf(X,Y,U)
d) For N = 8, 16, 32, record the number of the GS iteration in part c) and the error
eh = max
0≤i,j≤N
|u(xi, yj ) − Uij |

Note that the exact solution u(x, y) = 1 sin(πx) sin(πy).
e) Now suppose that the error eh ≈ Chα for some constants C and α. Then

eh1 e
hα


≈ hα
⇒ αk =
ln eh1


ln h
− ln eh2
−

ln h
How do the values of α computed in part (d) compare to the rates of con- vergence for these norms predicted by the theory? Make sure to hand in a copy of your program as m file and the values you computed of e1/8, e1/16, e1/32 and α.

Problem 2. a) Write a computer program to approximate the solution
of the boundary value problem:
−u + u = 1, 0 < x < 1, u(0) = 0 u(1) = 1.
by the finite element method using continuous piecewise linear elements on a uniform mesh of width h. Use h = 1/100 and 1/200.
b) Let uI (x) denote the piecewise linear interpolant of u, i.e., the piecewise linear function satisfying
uI (xi) = u(xi), i = 0, · · · , N, and e(x) = uI (x) − uh(x).
Let
E(1) = max
|e(xi)|,

h

E(2) =

0≤i≤N

0≤‘i≤N
/ ‘

h|e(xi)|
1/2
,


1/2



Have the computer determine E(1), E(2), E(3), for h = 1/100 and 1/200.
h h h
Note: the true solution of the boundary value problem is given by


ex e −x
u(x) = − 1 + e − 1 + e e + 1
c)


Now suppose that the error E(k) ≈ Ckhαk for some constants Ck and
αk. The error Eh gives an approximation to lu − uhlL2(0,1) and the error

Eh gives an approximation to l∇(u − uh)lL2(0,1). How do the values of α2
and α3 computed in part (c) compare to the rates of convergence for these
norms predicted by the theory? Make sure to hand in a copy of your program as m file and the values you computed of E1/100, E1/200, and α.