File tree 1 file changed +15
-13
lines changed
1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change 1
1
import numpy as np
2
+
3
+
2
4
def lanczos (A : np .ndarray ) -> ([float ], [float ]):
3
5
"""
4
- Implements the Lanczos algorithm for a symmetric matrix.
6
+ Implements the Lanczos algorithm for a symmetric matrix.
5
7
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).
10
12
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
+ """
18
20
n = A .shape [0 ]
19
21
V = np .zeros ((n , n ))
20
22
V [:, 0 ] = np .random .randn (n )
@@ -31,4 +33,4 @@ def lanczos(A: np.ndarray) -> ([float], [float]):
31
33
w -= beta [j - 1 ] * V [:, j - 1 ]
32
34
beta .append (np .linalg .norm (w ))
33
35
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