import numpy as np
import numpy.linalg as la
Let's make a matrix with given eigenvalues:
n = 5
np.random.seed(70)
eigvecs = np.random.randn(n, n)
eigvals = np.sort(np.random.randn(n))
A = np.dot(la.solve(eigvecs, np.diag(eigvals)), eigvecs)
print(eigvals)
Let's make an array of iteration vectors:
X = np.random.randn(n, n)
Next, implement orthogonal iteration:
Run this cell in-place (Ctrl-Enter) many times.
Q, R = la.qr(X)
X = np.dot(A, Q)
print(Q)
Now check that the (hopefully) converged \(Q\) actually led to Schur form:
la.norm(
np.dot(np.dot(Q, R), Q.T)
- A)
Do the eigenvalues match?
R
What are possible flaws in this plan?