Sparse Matrix Algorithms


Example: Minimum Residual Algorithm

For symmetric indefinite matrices it is best to use the minimum residual algorithm. The following example is slightly modified from the previous example by negating the first matrix element:


   /* minimum residual algorithm */

   /* value   row   col */
   A = { -3     1     1,
          1     2     1,
          4     2     2,
          1     3     2,
          3     4     2,
         10     3     3,
          3     4     4 };

   /* right-hand sides b = (1 1 1 1) */
   b = {1, 1, 1, 1};

   /* desired solution tolerance (optional) */
   tol = 1e-7;

   /* maximum number of iterations (optional) */
   maxit = 200;

   /* allocate iteration progress (optional) */
   hist = j(50, 1);

   /* initial guess (optional) */
   start = {2, 3, 4, 5};

   /* invoke minimum residual method */
   call itsolver (
     x, st, it,            /* output parameters */
     'minres', a, b, 'ic', /* input parameters */
     tol,                  /* optional control parameters */
     maxit,
     start,
     hist
    );

   print  x;  /* print solution */
   print st;  /* print solution tolerance */
   print it;  /* print resultant number of iterations */
                    X
                 -0.27027
                0.1891892
                0.0810811
                0.1441441

                    ST
                1.283E-15

                    IT
                        4