function [out, Elist]=pccg(W,Nit,cgform)
Input:
- W:
matrix containing initial guess for eigensolutions
- Nit: Number of iterations desired
- cgform: Version of cg: 1=Fletcher-Reeves, 2=Polak-Ribiere, 3=Hestenes-Stiefel
Output:
- out: Result of Nit iterations of preconditioned conjugate gradients
- Elist: Nit
1 column vector containing result of getE() after each iteration
- DISPLAY: result of each getE(), ``linmin test'' (angle cosine between
previous search direction and current gradient), ``conjugate gradient
test'' (angle cosine, measured through the preconditioner, of the
current gradient and the previous gradient)
Implement the preconditioned conjugate-gradients algorithm discussed
in lecture,
- Initialize
- Evaluate gradient:
- If not first iteration, do ``linmin test'': check
for
being the previous search direction
- If not first iteration, do ``cg test'': check
for
being the previous search direction
- Set search direction:
, where
- Fletcher-Reeves:
- Polak-Ribiere:
- Hestenes-Stiefel:
- Evaluate gradient at trial step:
- Compute estimate of best step:
-
- Repeat (2-8)
with a function of the above prototype in the file ``pccg.m''.
Hint: You may wish to use the ``if ... elseif ... elseif ... end'' octave construct.
Subsections
Tomas Arias
2007-04-26