> For the complete documentation index, see [llms.txt](https://ykkim.gitbook.io/EC/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ykkim.gitbook.io/EC/numerical-programming/ta-tutorial/tutorial-eigenvalue-problem.md).

# Tutorial: Eigenvalue problem

## Tutorial: MATLAB

Estimate the eigenvalue and eigenvectors

```matlab
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**

* [TU\_Eigenvalue\_Student\_2025.mlx](https://github.com/ykkimhgu/NumericalProg-student/blob/main/tutorial/TU_Eigenvalue/TU_Eigenvalue_Student_2025.mlx)

**Fill-In the blanks.**

```matlab
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);
    H=zeros(n,n);
    R=A;
    Q = I;    
    
    for j = 1:n-1                
        % Step 1. Create vector [c]
        % [YOUR CODE GOES HERE]
        % c = _______________;   
        

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

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

        % Step 4. Create matrix [H]
        % [YOUR CODE GOES HERE]
        % H = _______________;
        
        % Step 5. 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)**

```matlab
% 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**

* [Tutorial\_Eigenvalue\_Student.cpp](https://github.com/ykkimhgu/NumericalProg-student/blob/main/tutorial/TU_Eigenvalue/TU_Eigenvalue_Student.cpp)

**Create the function that returns the estimated eigenvalues**

```c
Matrix eigval_student(Matrix _A); // returns Nx1 vector
void QRdecomp_student(Matrix Q, Matrix R, Matrix _A);


// Usage example
Matrix eigVals = eigval_student(matA);  
```

## Exercise 3: Eigenvector in C-Programming

```c
Matrix eigvec_student(Matrix _A);
// Usage example
Matrix eigVec = eigvec_student(matA);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ykkim.gitbook.io/EC/numerical-programming/ta-tutorial/tutorial-eigenvalue-problem.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
