/* * CG 2x2 case with potitive definite assumption * based on Cholesky decomposition. * From wiki: https://en.wikipedia.org/wiki/Cholesky_decomposition * 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*. */ #include #include #define n 2 $input double a1,a2,a3; $input double b[n]; double x[n]; double xcg[n]; void cg(double A[n][n], double b[n], double x[n]) { double r[n]; //residual double p[n]; //search direction double temp[n]; double temp2[n]; double rsold; // double rsnew; double alpha; double beta; for (int i=0; i rsnew = 0.0; for (int i=0; i