MA580: Project #3, due Oct. 20 Problem 1 Prove Lemma 2 from the

MA580: Project #3, due Oct. 20
Problem 1 Prove Lemma 2 from the notes.
Problem 2 Consider the problem
−∆u = f
u=0
2
in Ω,
on ∂Ω,
2
∂
∂
where ∆ = ∂x
2 + ∂y 2 , Ω is an open, piecewise smooth simply connected two-dimensional domain defined
below and f is a known function on Ω.
1. Consider the case Ω = (0, 1)2 . Show that the standard second order discretization of the problem
with a uniform grid of size ∆x = 1/(n + 1) (and thus n2 inner nodes) can be written as
Tn U + U Tn = ∆x2 F
where the n × n matrices Tn , U and F are defined as


2 −1
0



 −1 . . . . . .
 , and Uij ≈ u(xi , yj ), Fij = f (xi , yj ),
Tn = 


..
..

. −1 
.
0
−1
2
with xi = i∆x and yj = j∆x, i, j = 1, . . . , N .
2. Show that the equation under point 1 can be rewritten as
AU = ∆x2 F
with A = In ⊗ Tn + Tn ⊗ In , U = vec(U ) and F = vec(F ).
3. Things get more complicated if Ω is not the academic square. Consider the code below to solve
the problem on an L-shaped domain Ω. Make sure you understand how MATLAB assembles the
matrix (you have nothing to turn in for this point).
4. Solve the above problem for the L-shaped case with n = 1000. Compare the performance of
Jacobi, CG, PCG by plotting (semilogy) the relative residual norm as a function of the number
of iterations (check whether your tolerance was satisfied). Hint: for CG and PCG just use the
pcg MATLAB routine. You can use incomplete Cholesky as a preconditioner (if so, provide a one
paragraph explanation –in your words– of what ichol does).
Problem 3 Consider the problem
1
,
2
u(0) = 0, u(1) = 1,
u00 (x) + u0 (x) =
∀x ∈ (0, 1),
for > 0.
1. Find the exact solution of the problem.
2. Apply a centered difference discretization with cell size ∆x to the above problem and rewrite the
resulting linear system as AU = F.
3. Describe the properties of the matrix A including its conditioning in terms of both and ∆x.
4. Using the backslash solver, for = .1 and n = 100 inner nodes, plot the numerical and exact
solution on the same system of axes. Find the numerical order of convergence with respect to ∆x.
5. For = 10−3 , plot the solution with both n = 100 and n = 1000. Explain what you observe.
6. Solve the n = 100 and = .1 case with the MATLAB gmres routine without preconditioning.
Discuss number of restarts, tolerance and maximum of iterations required to achieve convergence.
7. For the case n = 100, = .1, tol = 10−10 and maxit = 10, plot the residual histories in a semilog
plot (semilogy) for both gmres without preconditioning and gmres with the diffusion matrix,
i.e., without the convective term, as preconditioner. Compare and discuss.
8. Bonus: discuss what happens to the gmres convergence as gets smaller.
9. Bonus2 : numerically solve the above problem by applying CG to AT AU = AT F. Explain why the
method is called CGNR (Conjugate Gradient on the Normal equations to Minimize the Residual).
Compare with the above methods.
1
2
3
4
5
function e l l
global A
n=100;
dx = 1 / ( n+1) ;
R = ’L ’ ; % Other p o s s i b l e s h a p e s i n c l u d e S , N, C, D, A, H, B
6
7
8
[ A,N] = e l l m a t ( n ,R) ;
r h s = dx ˆ2∗ o n e s (N, 1 ) ;
9
10
11
12
13
% MATLAB b u i l t −i n s o l v e r
tic ;
u = A\ r h s ;
toc
14
15
16
17
18
19
20
21
% CG MATLAB
tic
%L = i c h o l (A) ;
L = i c h o l (A, s t r u c t ( ’ m i c h o l ’ , ’ on ’ ) ) ;
[ ucg , f l a g , r e l r e s , i t e r , r e s v e c ] = pcg (A, rhs , dx ˆ 2 , 1 0 0 , L , L ’ ) ;
%[ ucg , f l a g , r e l r e s , i t e r , r e s v e c ] = pcg (A, rhs , 1 e −6 ,100) ;
toc
22
23
24
25
26
27
G = numgrid (R, n ) ;
U = G;
U(G>0) = f u l l ( u (G(G>0) ) ) ;
mesh (U)
%c o n t o u r (U, 5 0 )
28
29
30
31
32
33
34
f u n c t i o n [ A,N] = e l l m a t ( n ,R)
% Generate and d i s p l a y t h e g r i d .
G = numgrid (R, n ) ;
%spy (G)
%g = numgrid (R, n )
35
36
37
A = d e l s q (G) ;
N = sum (G( : ) >0) ;
% d i s c r e t e Laplacian
% number o f i n n e r nodes