These exercises use Maple to illustrate how the conjugate gradient method works. The Maple setup files are in ~p6730/exercises/cg. Start Maple and use the command read `maplesd`; or read `maplecg`;.
We are solving the problem
A x = b
[ 5 4.5]
A := [ ]
[4.5 4.5]
[ 1 ] [ u ]
b := [ ] x := [ ]
[ -1 ] [ v ]
Note that the matrix is symmetric, so we can use simplified methods.
The contour plot shows the elevation of the function
f(x) = x * A x/2 - b*xwhich is minimum when x solves the linear system.
Hand in your Maple session. Also give your best answer (within the error of the method.)
Steepest descent algorithm
x0 = 0 (or any guess)
For k = 1 to MAX (until converged)
rk-1 = b - Axk-1
Stop when rk-1 = 0 (converged)
alphak = rk-1*rk-1/rk-1*A rk-1
xk = xk-1 + alphak rk-1
Loop
Hand in your Maple session. Also give your best answer (within the error of the method.) Comment on the difference between this method and steepest descent.
Conjugate gradient algorithm
x0 = 0 (or any guess)
r0 = b - A x0
p0 = r0
For k = 1 to MAX (until converged)
alphak = rk-1*rk-1/pk-1*A pk-1
xk = xk-1 + alphak pk-1
rk = rk-1 - alphak A pk-1
Stop when rk = 0 (converged)
betak = rk*rk/rk-1*rk-1
pk = rk + betak pk-1
Loop