Tutorial: Eigenvalue problem

Tutorial: MATLAB

Estimate the eigenvalue and eigenvectors

clear; close all;

A = [45 30 -25; 30 -24 68; -25 68 80];

disp('Eigvalue and vector of A (MATLAB):');
[eigVec,eigVal]=eig(A)
eigvalues=diag(eigVal)

Exercise 1: MATLAB

Download the tutorial source file

Fill-In the blanks.

function [Q, R] = QRdecomp_student(A)  
% Factorization of given matrix [A] into Upper triagular [R] and orthogonormal [Q]
% Using HouseHold Matrix
% Input: A (nxn)
% Output: Q (nxn), R (nxn)
    
    % Initialization
    n = size(A,1);
    I=eye(n);
    R=A;
    Q = I;    
    
    for j = 1:n-1                

        % Create vector [c]
        % [YOUR CODE GOES HERE]
        % c = _______________;   
        

        % Create vector [e]
        e=zeros(n,1);
        % [YOUR CODE GOES HERE]
        % e = _______________;
        

        % Create vector [v]
        % [YOUR CODE GOES HERE], HINT: use norm(c,2)
        % v = _______________;
    

        % Create matrix [H]
        % [YOUR CODE GOES HERE]
        % H = _______________;

        
        % Update [Q], [R]
        Q = Q*H;
        R = H*R;
    end

end % end of function

Run the code and check the answer with MATLAB's eig(A)

% initialize  
N=100;
U=A; 

for i = 1:N 
    % Step 1: A=QR decomposition
    [Q, R] = QRdecomp_student(U); 
    
    % Step 2: Create Similar Matrix A = Q'AQ
    U = R*Q;   
    if(~mod(i,10))                
        disp(sprintf('iteration %d \n',i));
        U
    end
end

% Step 3: eigenvalues from U
lamdas = diag(U);

Exercise 2: Eigenvalue in C-Programming

Download the tutorial source file

Create the function that returns the estimated eigenvalues

Matrix eigval(Matrix A);  // returns nx1 vector
void QRdecomp(Matrix A, Matrix Q, Matrix R); 

// Usage example
Matrix eigVals = eigval(matA);  

Exercise 3: Eigenvector in C-Programming

Matrix eigvec(Matrix A);

// Usage example
Matrix eigVec = eigvec(matA);

See the Assignment_Eigenvalue for more detail

Exercise 4: eig() in C-Programming

Matrix eig(Matrix A,Matrix V, Matrix D);

// Usage example
eig(matA,matV, matD);

See the Assignment_Eigenvalue for more detail

Last updated