# pcg: Preconditioned Conjugate Gradient algorithm for solving Ax=b In pcg: Preconditioned Conjugate Gradient Algorithm for solving Ax=b

## Description

The function solves linear system of equations Ax=b by Preconditioned Conjugate Gradient algorithm. Here matrix A must be real symmetric and positive definite. This can also be used to minimize the quadractic function (x'Ax)/2-bx.

## Usage

 `1` ```pcg(A, b, M, maxiter = 1e+05, tol = 1e-06) ```

## Arguments

 `A` A is real symmetric positive definite matrix of order n x n. `b` b is a vector of order n x 1. `M` Optionally a suitable preconditioner matrix specified by user `maxiter` Maximum number of iterations `tol` Tolerance for convergence of the solution

## Value

A vector of order n x 1

## Note

The algorithm does not check for symmetricity and positive definiteness of matrix A. Please ensure these conditions yourself.

## Author(s)

B N Mandal and Jun Ma

## References

Barrett, R., M. Berry, T. F. Chan, et al., (1994). Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods, SIAM, Philadelphia.

## Examples

 ```1 2 3 4``` ```A=matrix(rnorm(100*100,mean=10,sd=2),100,100) A=t(A)%*%A b=rnorm(100) pcg(A,b) ```

### Example output

```               [,1]
[1,]  -4.96560956
[2,]   3.05419176
[3,]   1.63063568
[4,]  -2.18459432
[5,]   1.21032034
[6,]   3.26355283
[7,]   3.93668599
[8,]  -9.13796637
[9,]  11.65146587
[10,]  -5.23377138
[11,]  13.93174518
[12,]   0.16054274
[13,]   4.73294896
[14,]   6.50665858
[15,]   7.10447518
[16,]   1.79857837
[17,]  -6.69538837
[18,]  -1.21559214
[19,]  -5.92581032
[20,]  -6.81361844
[21,]  -2.79639313
[22,]   1.62021616
[23,]   3.70009622
[24,]  -3.19388640
[25,] -14.05084729
[26,]  -1.85522249
[27,]  11.17982821
[28,]  -1.19679409
[29,] -11.38436192
[30,] -15.14559363
[31,]  17.02627447
[32,] -13.25885876
[33,]   0.94089797
[34,]  -4.09981102
[35,]   4.32297474
[36,]   4.46882818
[37,]  -4.94451999
[38,] -17.54230745
[39,]   0.61427055
[40,]   0.66549476
[41,]   4.11747453
[42,]  -2.79753298
[43,]   6.49912372
[44,]  -6.76038612
[45,]  -2.77430641
[46,]   7.54972018
[47,]  11.00250595
[48,]  -3.28564713
[49,] -11.91920424
[50,]   0.10118698
[51,]  -4.22532396
[52,]   1.97021932
[53,]   8.96777196
[54,]  -9.24191298
[55,]  -6.51947003
[56,]   4.07824534
[57,]   1.10269998
[58,]  12.74205604
[59,]   7.75945224
[60,]   1.83902669
[61,]   6.57911499
[62,]  -1.46020907
[63,]   9.39404534
[64,]  -3.77475572
[65,]   8.02208607
[66,]  -0.10143988
[67,]  -0.09957911
[68,]  -1.86762261
[69,]   2.69499642
[70,]  -4.60228116
[71,]  -4.15979847
[72,]  -6.48434535
[73,]   6.30554143
[74,]   3.22293433
[75,]   2.48350616
[76,]   0.83659425
[77,]  -5.25165746
[78,]  -3.40364844
[79,]   1.73630618
[80,]   2.55646064
[81,]   1.64049113
[82,]   0.64933086
[83,]  10.10440556
[84,]  -7.51844897
[85,]   3.74710674
[86,]  10.13272057
[87,]   1.70747368
[88,]   8.48573246
[89,] -11.24083905
[90,]  11.17453306
[91,]  13.28371648
[92,] -11.97890216
[93,]   0.29600168
[94,]   2.66890762
[95,]  -9.21662910
[96,] -13.38643529
[97,]   1.81879652
[98,]  -1.09208063
[99,] -17.18064727
[100,]   5.06407462
```

pcg documentation built on May 2, 2019, 8:19 a.m.