Skip to content

Instantly share code, notes, and snippets.

@andrenarchy
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save andrenarchy/9783314 to your computer and use it in GitHub Desktop.

Select an option

Save andrenarchy/9783314 to your computer and use it in GitHub Desktop.
import numpy
from krypy import linsys
m = 10
n = 5
A = numpy.random.rand(m, m)
A = A + A.T
B = numpy.random.rand(n, m)
Z = numpy.zeros((n, n))
tau = 1e-4
f = numpy.ones((n+m, 1))
ls1 = linsys.LinearSystem(numpy.bmat([[A, -tau*B.T], [B, Z]]), f)
sol1 = linsys.Gmres(ls1, tol=0.5)
x1 = sol1.xk
ls2 = linsys.LinearSystem(numpy.bmat([[A, B.T], [B, Z]]), f)
sol2 = linsys.Gmres(ls2, tol=0.5)
x2 = sol2.xk
x2[m:] /= -tau
print(x1 - x2)
print(len(sol1.resnorms))
print(len(sol2.resnorms))
'''The above results in
[[ 1.76809663e-02]
[ 1.76809663e-02]
[ 1.76809663e-02]
[ 1.76809663e-02]
[ 1.76809663e-02]
[ 1.76809663e-02]
[ 1.76809663e-02]
[ 1.76809663e-02]
[ 1.76809663e-02]
[ 1.76809663e-02]
[ 8.46503582e+02]
[ 8.46503582e+02]
[ 8.46503582e+02]
[ 8.46503582e+02]
[ 8.46503582e+02]]
2
2
The last lines mean that one iteration was carried out for both linear systems.
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment