Tried to fix lanczos implementation

Still solution far from correct.
This commit is contained in:
alberto
2026-03-22 20:14:29 +01:00
parent 1ae5d329f2
commit d89e683110
3 changed files with 61 additions and 12 deletions
+27
View File
@@ -0,0 +1,27 @@
import numpy as np
import numpy.linalg as LA
from afgl.lanczos import lanczos
"""
Todo: better test case
"""
def test_lanczos_return_correct_solution():
N = 6
M = 4
A = np.random.randint(1, 10, size=(N, N))
L = (A + A.T) / 2
s = np.random.randint(1, 10, N)
[V, alp, beta] = lanczos(L, s, M)
T = np.diag(alp) + np.diag(beta, -1) + np.diag(beta, 1)
x = LA.solve(A, s)
e_1 = np.zeros(M)
e_1[0] = 1
y = (LA.inv(T) @ e_1) * LA.norm(s)
x_lanczos = V @ y
assert LA.norm(x - x_lanczos) < 1e-3