💾
EC
  • Introduction
  • EC Course
    • Syllabus
    • Preparation for EC
    • Tutorial
      • Tutorial: arduino-stm32
        • Tutorial: arduino-stm32 Installation
        • Tutorial: arduino-stm32 Part1
        • Tutorial: arduino-stm32 Part2
      • Tutorial: MDK uVision
        • Tutorial: Installing MDK uVision
        • Tutorial: Create a Project with uVision
        • Tutorial: Adding library header in uVision
        • Tutorial: Re-using Project Configuration
        • Debugging in uVision
      • Tutorial: PlatformIO in CLion
      • Tutorial: PlatformIO in VSCode
      • Tutorial: Repository Management
      • Tutorial: Managing library header files
      • Tutorial: PinName Configuration
      • Tutorial: Bitwise Macro
      • Tutorial: Custom initialization
      • Tutorial: Documentation
      • Tutorial: Creating Application API
      • Tutorial: 7-Segment Display
      • Tutorial: DC motor driver connection
      • Tutorial: USART with TeraTerm
      • Tutorial: Finite State Machine programming
      • Tutorial: Bluetooth
      • Tutorial: Zigbee with Nucleo board
    • LAB
      • LAB Report Template
      • LAB: Smart mini-fan with STM32-duino
      • LAB: Portable Fan with mbed
      • LAB: GPIO Digital InOut
      • LAB: GPIO Digital InOut 7-segment
      • LAB: EXTI & SysTick
      • LAB: Timer & PWM
      • LAB: Stepper Motor
      • LAB: Input Capture - Ultrasonic
      • LAB: USART - LED, Bluetooth
      • LAB: ADC - IR reflective sensor
      • LAB: Line Tracing RC Car
    • Sample code
      • Code Templates
    • Hardware
      • Nucleo-F411RE
      • LAB Hardware
        • Electronic Chips
        • HUINS Embedded Kit
    • Projects
      • Line Tracing Car Project
      • Design Project
        • Past Projects
      • Project Grading Criteria
    • Study Resource for MCU
      • Hexa-Decimal Table
      • Bitwise Op for Register
      • System Clock
      • Timer
      • USART
      • ADC
  • STM32 M4 Programming
    • Documentation
      • C++ API Docs
    • Firmware Library
      • PinName Configuration
      • GPIO Digital
      • RCC
      • EXTI_SysTick
      • TIMER
      • USART
    • Troubleshooting
    • mbed for STM32
      • Tutorial: mbed-Part 1
      • Tutorial: mbed - Part 2
      • Tutorial: mbed - Part 3
      • Using mbed API on uVision
    • mbed OS
  • Other Programming
    • Arduino
    • Socket Programming
      • Window Socket Programming
      • Arduino WiFi
    • Cube-MX
    • Github
    • Markdown
      • Example: API documentation
    • MATLAB
  • C Programming
    • C-Programming Lessons
      • Installing Visual Studio Community
        • Visual Studio Community 2022
      • Installing VS Code(Mac/Linux)
      • Creating Header Lib
      • Pointer
      • Array
      • 2D Array
      • Structure
      • Dynamic Alloc
      • Bitwise Operation
  • Numerical Programming
    • Syllabus
    • Preparation for NP
    • Math Review
    • Tutorial
      • TA Session Video
      • Tutorial: NP Library Header Files
      • Tutorial - Sine Taylor
      • Tutorial: Passing a Function, Function callback
      • Tutorial: Nonlinear solver
      • Tutorial: Differentiation
      • Tutorial: Integration
      • Tutorial: Matrix Structure
      • Tutorial: Eigenvalue problem
      • Tutorial: ODE-IVP
      • Tutorial: Curve Fitting
      • Tutorial: Create Github Repos of NP lib
      • Tutorial: Version Control in Github
      • Tutorial: Documentation with Markdown
      • Exercise: Version Control and Documentation
    • Example: MATLAB
    • Example: NP Library
    • Assignment
      • Assignment Factorial and Power
      • Assignment: Version Control and Documentation
    • Problem Bank
Powered by GitBook
On this page
  • Tutorial: MATLAB
  • Exercise 1: MATLAB
  • Exercise 2: Eigenvalue in C-Programming
  • Exercise 3: Eigenvector in C-Programming
  • Exercise 4: eig() in C-Programming

Was this helpful?

  1. Numerical Programming
  2. Tutorial

Tutorial: Eigenvalue problem

PreviousTutorial: Matrix StructureNextTutorial: ODE-IVP

Last updated 6 months ago

Was this helpful?

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

TU_Eigenvalue_Student_2024.mlx
Assignment_Eigenvalue_ID.cpp