Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

YEUNGKAWING20353855_4

function PowerIter

n=500;
A=randn(n,n);
A=(A+A')/2;

for testtime=1:5
    y0=randn(n,1);
    y0=y0/norm(y0);
    [mu,y]=Power(A,y0);
    % Store mu and y
    mu1(testtime)=mu;
    y1(:,testtime)=y;
end
% Display the results
disp('The computed eigenvalues are shown below. You will see they are almost the same.')
disp(mu1)
disp('The inner products of computed eigenvectors are shown below.');
disp('You will see some are close to 1, and some are close to -1.');
disp('This shows that the computed vectors may be in opposite direction'); 
disp('but both are the same eigenvector.')
disp(y1'*y1)

% Below is the subroutine of power iteration.     
    function [mu,y]=Power(A,y0)
        maxit=10^4;
        epsilon=1e-6;
        y=y0;
        for iter=1:maxit
            %%%%%%% 
            %Insert your lines for Power Iteration
            m^(k)=A*y^(k-1)
            y^(k)=m^(k)/abs (m^k)_2
            U^(k)=(y^(k))'*A*(y^(k)) 
            
            
            %%%%%%%
            % Check: if ||Ay^k - mu^k y^k ||_2<= epsilon, then break the
            % for loop.
            % Complete the following line
            if 
            abs (A*y^k - m*u^k y^k)_2 <= epsilon
                break;
            end
        end
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    end

end

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.