File tree Expand file tree Collapse file tree 1 file changed +15
-13
lines changed
Expand file tree Collapse file tree 1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change 11import numpy as np
2+
3+
24def lanczos (A : np .ndarray ) -> ([float ], [float ]):
35 """
4- Implements the Lanczos algorithm for a symmetric matrix.
6+ Implements the Lanczos algorithm for a symmetric matrix.
57
6- Parameters:
7- -----------
8- matrix : numpy.ndarray
9- Symmetric matrix of size (n, n).
8+ Parameters:
9+ -----------
10+ matrix : numpy.ndarray
11+ Symmetric matrix of size (n, n).
1012
11- Returns:
12- --------
13- alpha : [float]
14- List of diagonal elements of the resulting tridiagonal matrix.
15- beta : [float]
16- List of off-diagonal elements of the resulting tridiagonal matrix.
17- """
13+ Returns:
14+ --------
15+ alpha : [float]
16+ List of diagonal elements of the resulting tridiagonal matrix.
17+ beta : [float]
18+ List of off-diagonal elements of the resulting tridiagonal matrix.
19+ """
1820 n = A .shape [0 ]
1921 V = np .zeros ((n , n ))
2022 V [:, 0 ] = np .random .randn (n )
@@ -31,4 +33,4 @@ def lanczos(A: np.ndarray) -> ([float], [float]):
3133 w -= beta [j - 1 ] * V [:, j - 1 ]
3234 beta .append (np .linalg .norm (w ))
3335 V [:, j + 1 ] = w / beta [j ]
34- return alpha , beta
36+ return alpha , beta
You can’t perform that action at this time.
0 commit comments