/* * CG 3x3 case with potitive definite assumption based on Cholesky decomposition. * From wiki: * The matrix M is positive definite if and only if there exists a unique lower * triangular matrix L, with real and strictly positive diagonal elements, such * that M = LL*. This factorization is called the Cholesky decomposition of M. */ #include #include #define n 3 $input double diag1,diag2,diag3,off1,off2,off3; $input double b[n]; double x[n]; double xcg[n]; void cg(double A[n][n], double b[n], double x[n], int steps) { double r[n]; double p[n]; double temp[n]; double tempp[n]; double rsold; double rsnew; double rsfrac; double alpha; // x = 0 for(int i=0; i rsold = 0.0; for(int i=0; i rsnew = 0.0; for(int i=0; i