Conjugate gradient algorithm

### 14.6.4 Conjugate gradient algorithm

The conjugate_gradient command uses the conjugate gradient algorithm to solve a linear system of equations.

- conjugate_gradient takes two mandatory arguments and two optional arguments.
  - A, an n× n positive definite symmetric matrix.
  - y, a vector of length n.
  - Optionally, x0, a vector of length n, an initial approximation.
  - ε, a positive number (by default epsilon, see Section 2.5.7, item 2.5.7).
- conjugate_gradient(A,y ⟨,x0,ε⟩) returns the solution to Ax=y to within ε.

#### Examples

We can solve the system {

2x+y=1
x+5y=0

by entering one of the following commandlines.

conjugate_gradient([[2,1],[1,5]],[1,0])

| ⎡ ⎢ ⎢ ⎣ |
5
9
| ,− |
1
9
| ⎤ ⎥ ⎥ ⎦

conjugate_gradient([[2,1],[1,5]],[1,0],[0.55,-0.11],1e-2)

| ⎡ ⎣ | 0.555,−0.11 | ⎤ ⎦

conjugate_gradient([[2,1],[1,5]],[1,0],[0.55,-0.11],1e-10)

| ⎡ ⎣ | 0.555555555556,−0.111111111111 | ⎤ ⎦