Conjugate gradient method (source code)

= Conjugate gradient method
{c}
{wiki}

For a <positive-definite matrix> $A$, the conjugate gradient method chooses mutually $A$-conjugate search directions. Starting with $r_0=b-Ax_0$ and $p_0=r_0$, it uses
$$
\alpha_k=\frac{r_k^Tr_k}{p_k^TAp_k},\quad
x_{k+1}=x_k+\alpha_kp_k,\quad
r_{k+1}=r_k-\alpha_kAp_k,
$$
and $p_{k+1}=r_{k+1}+\beta_kp_k$ with
$\beta_k=r_{k+1}^Tr_{k+1}/(r_k^Tr_k)$.