Question: Problem 4 Define a function norm _ approx _ gen ( ( mathbf { M } , mathbf { x }
Problem
Define a function normapproxgen mathbfMmathbfxmathbfmathbfk that approximates the dominant eigenvector and eigenvalue of any square matrix. Your function should take as input a square matrix m of any size, as well as an initial guess mathbfxmathbf and integer mathbfk and use the power iteration method described above to approximate the dominant eigenvector and eigenvalue of mathbfm up to the k th iterate.
Your function should normalize at each step by dividing the eigenvector approximation by the largest absolute value of its entries. You function should return the approximation mathbfxk of the eigenvector obtained in this way, as well as the eigenvalue approximation obtained by dividing the first entries of mathbfwk and mathbfxk
Quick Note
The command npabs a returns a vector whose entries are the absolute value of the entries in the NumPy vector a The command np max a returns the maximum element of the NumPy vector a You should also check this against simple examples for which you can compute eigenvalues by hand, perhaps a times matrix from the homework. Keep in mind that power iteration will only work for matrices that have a dominant eigenvalue.
Test Cases
You can test that your code is correct by evaluating these commands and comparing outputs:
normapproxgennparray nparray
array
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
