40
40
# QREig_val=np.array(QREig_val)
41
41
# QREig_vec=QREig_vec[:, index_sort]
42
42
# QREig_val=QREig_val[index_sort]
43
- # print(f"The maximum of the difference between the eigenvalue computed by numpy on A and the developed QR algorithm computed"
43
+ # print(f"The maximum of the difference between the eigenvalue computed by numpy on A and the developed QR algorithm computed"
44
44
# f"on the Matrix T is {np.linalg.norm(npEig_val-QREig_val, np.inf)}")
45
45
46
46
47
-
48
47
# def check_column_directions(A, B):
49
48
# n = A.shape[1]
50
49
# for i in range(n):
51
50
# # Normalize the vectors
52
- # a = A[:, i]
53
- # b = B[:, i]
51
+ # a = A[:, i]
52
+ # b = B[:, i]
54
53
# dot = np.dot(a, b)
55
54
# # Should be close to 1 or -1
56
55
# if dot<0:
57
- # B[:, i] = -B[:, i]
58
-
56
+ # B[:, i] = -B[:, i]
57
+
59
58
60
59
# check_column_directions(QREig_vec, LaEig_vec )
61
60
# print(f"The maximum absoulute error among the components of all the eigenvectors of T is {np.max(np.abs(QREig_vec - LaEig_vec))}")
142
141
143
142
# #Time scaling QR
144
143
145
- i_max = 12
144
+ i_max = 12
146
145
147
- time_vector = np .array ([])
148
- error_eigenvalue = np .array ([])
146
+ time_vector = np .array ([])
147
+ error_eigenvalue = np .array ([])
149
148
for i in range (3 , i_max ):
150
- n = 2 ** i
151
- #np.random.seed(42)
149
+ n = 2 ** i
150
+ # np.random.seed(42)
152
151
d = np .random .rand (n )
153
- off_d = np .random .rand (n - 1 )
154
- T = np .diag (d ) + np .diag (off_d , 1 ) + np .diag (off_d , - 1 )
155
- npEig_val , _ = np .linalg .eigh (T )
156
- t_s = time ()
157
- QREig_val , QREig_vec = QR_algorithm (d , off_d )
158
- t_e = time ()
159
- index_sort = np .argsort (QREig_val )
160
- QREig_vec = np .array (QREig_vec )
161
- QREig_val = np .array (QREig_val )
162
- QREig_vec = QREig_vec [:, index_sort ]
163
- QREig_val = QREig_val [index_sort ]
164
- error_eigenvalue = np .append (error_eigenvalue , np .linalg .norm (np .abs (npEig_val - QREig_val ), np .inf ))
165
- time_vector = np .append (time_vector , t_e - t_s )
152
+ off_d = np .random .rand (n - 1 )
153
+ T = np .diag (d ) + np .diag (off_d , 1 ) + np .diag (off_d , - 1 )
154
+ npEig_val , _ = np .linalg .eigh (T )
155
+ t_s = time ()
156
+ QREig_val , QREig_vec = QR_algorithm (d , off_d )
157
+ t_e = time ()
158
+ index_sort = np .argsort (QREig_val )
159
+ QREig_vec = np .array (QREig_vec )
160
+ QREig_val = np .array (QREig_val )
161
+ QREig_vec = QREig_vec [:, index_sort ]
162
+ QREig_val = QREig_val [index_sort ]
163
+ error_eigenvalue = np .append (
164
+ error_eigenvalue , np .linalg .norm (np .abs (npEig_val - QREig_val ), np .inf )
165
+ )
166
+ time_vector = np .append (time_vector , t_e - t_s )
166
167
167
168
print (error_eigenvalue )
168
- p = np .polyfit ([2 ** i for i in range (3 , i_max )], time_vector , 3 )
169
+ p = np .polyfit ([2 ** i for i in range (3 , i_max )], time_vector , 3 )
169
170
print (p )
170
- plt .plot ([2 ** i for i in range (3 , i_max )], time_vector , 'ko' )
171
- x = np .linspace (2 ** 3 , 2 ** (i_max - 1 ))
171
+ plt .plot ([2 ** i for i in range (3 , i_max )], time_vector , "ko" )
172
+ x = np .linspace (2 ** 3 , 2 ** (i_max - 1 ))
172
173
plt .plot (x , np .polyval (p , x ))
173
174
plt .show ()
174
175
211
212
# axs[1].grid(True, which="both")
212
213
# axs[1].set_xlabel('Tolerance ($\epsilon$)', fontsize=15)
213
214
# plt.tight_layout()
214
- # plt.show()
215
+ # plt.show()
0 commit comments