In [3]:
import numpy as np
from scipy import sparse
import matplotlib.pyplot as plt
import scipy.linalg as sla
%matplotlib inline

from arnoldi import arnoldi
In [4]:
A = sla.toeplitz([2, -1, 0, 0])
print(A)
[[ 2 -1  0  0]
 [-1  2 -1  0]
 [ 0 -1  2 -1]
 [ 0  0 -1  2]]
In [13]:
#r0 = np.ones((4,))
r0 = np.random.rand(4)
V, H = arnoldi(A, 3, v0=r0)
In [14]:
print(V)
print(H)
[[ 0.36042953  0.24808077  0.47810447]
 [ 0.11696572 -0.93499364  0.33235534]
 [ 0.76404769  0.16028752  0.2518489 ]
 [ 0.52215007 -0.19634343 -0.77299946]]
[[  9.39054304e-01   1.06993556e+00  -8.88178420e-16]
 [  1.06993556e+00   2.82658630e+00   7.20129425e-01]
 [  0.00000000e+00   7.20129425e-01   1.90415033e+00]]
In [15]:
print(np.sort(sla.eigvals(H).real))
print(np.sort(sla.eigvals(A).real))
[ 0.39181127  1.70575679  3.57222288]
[ 0.38196601  1.38196601  2.61803399  3.61803399]
In [ ]: