Next: , Previous: nzmax, Up: Function Reference


22.6.2.16 pcg

— Function File: x = pcg (a, b, tol, maxit, m, x0, ...)
— Function File: [x, flag, relres, iter, resvec, eigest] = pcg (...)

Solves the linear system of equations a * x = b by means of the Preconditioned Conjugate Gradient iterative method. The input arguments are

The arguments which follow x0 are treated as parameters, and passed in a proper way to any of the functions (a or m) which are passed to pcg. See the examples below for further details. The output arguments are

Let us consider a trivial problem with a diagonal matrix (we exploit the sparsity of A)

          	N = 10;
          	A = diag([1:N]); A = sparse(A);
          	b = rand(N,1);
     

Example 1: Simplest use of pcg

            x = pcg(A,b)
     

Example 2: pcg with a function which computes a * x

            function y = applyA(x)
              y = [1:N]'.*x;
            endfunction
          
            x = pcg('applyA',b)
     

Example 3: Preconditioned iteration, with full diagnostics. The preconditioner (quite strange, because even the original matrix a is trivial) is defined as a function

            function y = applyM(x)
              K = floor(length(x)-2);
              y = x;
              y(1:K) = x(1:K)./[1:K]';
            endfunction
          
            [x, flag, relres, iter, resvec, eigest] = pcg(A,b,[],[],'applyM')
            semilogy([1:iter+1], resvec);
     

Example 4: Finally, a preconditioner which depends on a parameter k.

            function y = applyM(x, varargin)
            K = varargin{1};
            y = x; y(1:K) = x(1:K)./[1:K]';
            endfuntion
          
            [x, flag, relres, iter, resvec, eigest] = ...
                 pcg(A,b,[],[],'applyM',[],3)
     

References

[1] C.T.Kelley, 'Iterative methods for linear and nonlinear equations', SIAM, 1995 (the base PCG algorithm)

[2] Y.Saad, 'Iterative methods for sparse linear systems', PWS 1996 (condition number estimate from PCG) Revised version of this book is available online at http://www-users.cs.umn.edu/~saad/books.html

     
     
See also: sparse, pcr.