[SciPy-user] Convergence behaviour of iterative solvers

Ed Schofield edschofield at gmail.com
Mon Jan 22 05:55:50 EST 2007


On 1/19/07, Nils Wagner <nwagner at iam.uni-stuttgart.de> wrote:
>
>
> So how can I use this functionality within the following
> script
> from scipy import *
>
> def func(x):
>      return 0.5*dot(x,dot(A,x))-dot(x,b)
>
> def callback(x):
>      return linalg.norm(dot(A,x)-b)
>
> n = 10
> x0 = zeros(n,float)
> A = random.rand(n,n)+diag(4*ones(n))
> A = 0.5*(A+A.T)
> b = random.rand(n)
>
> x = optimize.fmin_cg(func,x0)


Hi Nils,

The callback function's return value is ignored. Make it do something, e.g.:

def callback(x):
    print "||A.x - b|| = " + str(linalg.norm(dot(A,x)-b))

Then call it with:

x = optimize.fmin_cg(func, x0, callback=callback)

-- Ed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20070122/08e9530a/attachment.html>


More information about the SciPy-User mailing list