[Scipy-tickets] [SciPy] #385: iterative solver tolerance error

SciPy scipy-tickets@scipy....
Thu Mar 8 15:57:22 CST 2007

#385: iterative solver tolerance error
 Reporter:  wnbell        |       Owner:  somebody                       
     Type:  defect        |      Status:  new                            
 Priority:  normal        |   Milestone:                                 
Component:  scipy.linalg  |     Version:  devel                          
 Severity:  normal        |    Keywords:  iterative cg residual tolerance
 In the docs for CG the '''tol''' parameter pertains to the relative
 residual when in practice it seems related to the absolute residual.
 Consider the following test:

 import scipy,numpy,scipy.sparse,scipy.linalg

 def poisson_problem(N):
     Return a sparse CSC matrix for the 2d N*N poisson problem
     with standard 5-point finite difference stencil
     D = 4*numpy.ones(N*N)
     T =  -numpy.ones(N*N)
     O =  -numpy.ones(N*N)
     T[N-1::N] = 0
     return scipy.sparse.spdiags([D,O,T,T,O],[0,-N,-1,1,N],N*N,N*N)

 A  = poisson_problem(100)
 b  = numpy.zeros(A.shape[0])
 x0 = 1e3*scipy.rand(A.shape[0])

 print "initial residual",scipy.linalg.norm(b - A*x0)
 x,info = scipy.linalg.iterative.cg(A,b,x0=x0,tol=1e-8)
 print "initial residual",scipy.linalg.norm(b - A*x0)
 print "final residual",scipy.linalg.norm(b - A*x)


 initial residual 128502.741326
 initial residual 9.51887593104e-09
 final residual 9.51887593104e-09

 Also, x0 is also overwritten in the process.  Is this the intended

Ticket URL: <http://projects.scipy.org/scipy/scipy/ticket/385>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list