Previous Up Next

5.58.4  The conjugate gradient algorithm: conjugate_gradient

The conjugate_gradient command takes two mandatory arguments and two optional arguments. The mandatory arguments are an n× n positive definite symmetric matrix A and a vector y of length n. The optional arguments are a vector x0 of length n and a positive number є.
conjugate_gradient uses the conjugate gradient algorithm to return the solution to Ax = y to within є or epsilon. The vector x0 is an optional initial approximation.
Input:

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

Output:

[5/9,-1/9]

Input:

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

Output:

[0.555,-0.11]

Input:

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

Output:

[0.555555555556,-0.111111111111]

Previous Up Next