Write a function in Matlab that takes as input the number of iterations k, the size n, and a sparse matrix A. Have this function run the Power method for k iterations on an initial guess the vector of 1’s and output the dominant eigenvalue and its corresponding eigenvector. Use only basic programming.
Write out or print out your function.
Ans :
function [m, n] = PowerMethod (k, A, n)
for i = 1:k
m1 = zeros(n,1);
for j = 1:n
for q =
1:n
m1(j) = m1(j) + A(j,q) * m(q);
end
end
n = 0;
for j = 1:n
if
abs(m1(j)) > abs(n)
n = m1(j);
end
end
m = m1 / n;
end
end
Get Answers For Free
Most questions answered within 1 hours.