/* * Simple implementation of Conjugate Gradient algorithm for 2x2 * symmetric matrix. Instead of assuming positive-definite-ness, * we assume that in every division, the denominator is non-0. * Based on https://en.wikipedia.org/wiki/Conjugate_gradient_method */ #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