Question: Problem 4 Define a function norm _ approx _ gen ( M , x _ 0 , k ) that approximates the dominant eigenvector and

Problem 4
Define a function norm_approx_gen ( M,x_0,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
x00 and integer k, and use the power iteration method described above to
approximate the dominant eigenvector and eigenvalue of 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 x_(k) of the eigenvector obtained in this way, as well as
the eigenvalue approximation obtained by dividing the first entries of w_(k) and
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 3xx3 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)

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!