Question: Problem 4 Define a function norm _ approx _ gen ( ( mathbf { M } , mathbf { x }

Problem 4
Define a function norm_approx_gen (\(\mathbf{M},\mathbf{x}\_\mathbf{0},\mathbf{k}\)) 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 \(\mathbf{x}\mathbf{0}0\) and integer \(\mathbf{k}\), and use the power iteration method described above to approximate the dominant eigenvector and eigenvalue of \(\mathbf{m}\) 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 \(\mathbf{x}_{k}\) of the eigenvector obtained in this way, as well as the eigenvalue approximation obtained by dividing the first entries of \(\mathbf{w}_{k}\) and \(\mathbf{x}_{k-1}\).
Quick Note
The command np.abs (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 \(3\times 3\) 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:
norm_approx_gen(np.array([[2,4,6],[4,8,0],[1,2,9]]), np.array([1,5,-1]),10)
(array([0.98994349,1.,0.98491523]),12.01744017467949)
Problem 4 Define a function norm _ approx _ gen (

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!