Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python 7) Write code to implement the matrix iteration scheme for computing the dominant eigenvalue/eigenvector of a square matrix. In [ ]: def dominant_eigen_iteration(A, uo,
Python
7) Write code to implement the matrix iteration scheme for computing the dominant eigenvalue/eigenvector of a square matrix. In [ ]: def dominant_eigen_iteration(A, uo, tol, max_iters): compute dominant eigenvctor and eigenvalue for square matrix Args: A: nxn numpy array representing a matrix u0: initial estimate of eigenvector (1D numpy array) tol: float relaitve error termination criterion max_iters: integer iteration count termination criterion Returns: P,L,U: nxn numpy arrays permutation, lower triangular, upper triangular OUR CODE HERE raise NotImplementedError() In [ ]: A = np.array( [[2,-1,0,0],[-1,2,-1,0],[0,-1,2,-1],[0,0,-1,2]]). u = np.array([1,1,2,1]). tol = 0.001 max_iters = 100 W, V = dominant_eigen_iteration(A, uo, tol, max_iters) expected_v np.array( [-0.3717, 0.6015, -0.6015, 0.3717]) expected_w = 3.618 assert_(np.allclose(v, expected_v, atol=2e-01) or np.allclose(-v, expected_v, atol=2e-01)) assert_(abs (w expected_w)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started