Minor fix to breakdown.

master
alberto 1 month ago
parent a57b1a4496
commit ec756aaf8d

@ -1,26 +1,25 @@
import numpy as np import numpy as np
import numpy.linalg as LA import numpy.linalg as LA
"""
Classic Lanczos method (without re-orthogonalization)
Arguments
L : Real valued NxN symmetric matrix
s : vector of size N
M : natural number indicating basis size
Returns
-------
V : ndarray
M-dimensional vector with orthonormal columns.
alp : ndarray
M-dimensional array of scalars.
beta : ndarray
M-dimensional array of scalars.
"""
def lanczos(L, s, M): def lanczos(L, s, M):
"""
Classic Lanczos method (without re-orthogonalization)
Arguments
L : Real valued NxN symmetric matrix
s : vector of size N
M : natural number indicating basis size
Returns
-------
V : ndarray
M-dimensional vector with orthonormal columns.
alp : ndarray
M-dimensional array of scalars.
beta : ndarray
M-dimensional array of scalars.
"""
N = len(s) N = len(s)
alp = np.zeros(M) alp = np.zeros(M)
beta = np.zeros(M - 1) beta = np.zeros(M - 1)
@ -37,8 +36,9 @@ def lanczos(L, s, M):
if j < M - 1: if j < M - 1:
beta[j] = LA.norm(w) beta[j] = LA.norm(w)
if beta[j] == 0: if beta[j] < 1e-14:
break print("BREAKDOWN")
return V[:, : j + 1], alp[: j + 1], beta[:j]
V[:, j + 1] = w / beta[j] V[:, j + 1] = w / beta[j]
return [V, alp, beta] return V, alp, beta

Loading…
Cancel
Save