Multigrid |
We consider the Poisson equation in 1-D:
-u'' = f in (0,1) and u(0)=u(1)=0. (1)Given a uniform grid T_N of (0,1), we shall test several iterative methods for solving the linear system obtained by linear finite element approximation of (1).
The tri-diagonal matrix using sparse matrix can be generated by
e = ones(n,1)/h; A = spdiags([-e 2*e -e], -1:1, n, n);
Hint: you can implement the matrix form of these methods. Check these related functions in MATLAB: diag, tril, triu
Hint: You can use direct solver to compute the exact solution for a given right hand side (rhs) or plug in an exact solution to get a rhs. The error in the energy norm can be computed by matrix mutiplication.
Hint: To include all frequency into the error vector, you can set the rhs as a constant vector and choose a random initial guess.
Hint: To stop the iteration, you can compute the relative residual in l2 norm: norm(b-A*u)/norm(b) or the relative error in the energy norm: sqrt((uexact-u)'A*(uexact-u))/sqrt(uexact'*A*uexact) provide the exact solution is avaiable.
Hint: Code PCG with diagonal preconditioner first and make your PCG works well. Then try to use V-cycle MG as the preconditioner.
-u''+ u^3 = 1 in (0,1), u'(0) = u'(1) = 0.Compare the convergence and computaitonal cost with Newton's method.