Skip to main content

Manual Code for Eigenvalue Decomposition in MATLAB


MATLAB Code for Manual Eigenvalue Decomposition

clc;
clear;
close all;

A = [1,2];
R = A' * A;
array_length = length(A);
eigenvalues = manual_eigenvalue_decomposition(R, array_length);
disp('Eigenvalues:');
disp(eigenvalues);

eigenvectors = find_eigenvectors(R, eigenvalues);
disp('Eigenvector Matrix:');
disp(eigenvectors);

% Manual Eigenvalue Decomposition Function
function eigenvalues = manual_eigenvalue_decomposition(A, n)
eigenvalues = zeros(n, 1); % Initialize eigenvalues as a column vector
for i = 1:n
% Start with a random vector
v = randn(n, 1);

% Power iteration to find the eigenvector corresponding to the largest eigenvalue
for j = 1:10 % Iteration count (power iteration steps)
v = A * v; % Multiply by matrix A
v = v / norm(v); % Normalize the vector
end

% Eigenvalue is the Rayleigh quotient
eigenvalues(i) = (v' * A * v) / (v' * v);

% Deflate the matrix to find the next eigenvector
A = A - eigenvalues(i) * (v * v');
end
end

function eigenvectors = find_eigenvectors(A, eigenvalues)
n = size(A, 1); % Get the size of the matrix A
num_eigenvalues = length(eigenvalues); % Get the number of eigenvalues
eigenvectors = zeros(n, num_eigenvalues); % Initialize eigenvectors matrix

for i = 1:num_eigenvalues
lambda = eigenvalues(i); % Take the eigenvalue

% Solve (A - lambda * I) * v = 0
eig_matrix = A - lambda * eye(n); % (A - lambda * I)

% Find the null space (eigenvector corresponding to the eigenvalue)
v = null(eig_matrix);

% If there are multiple eigenvectors, select the first one
if size(v, 2) > 1
v = v(:, 1);
end

% Normalize the eigenvector
eigenvectors(:, i) = v / norm(v);
end
end

 

Output

Eigenvalues:
    5.0000
   -0.0000

Eigenvector Matrix:
    0.4472   -0.8944
    0.8944    0.4472 

 

MATLAB Code for Manual Eigenvalue Decomposition with Scaling of the Input Matrix R

clc;
clear;
close all;

A = [1,2];
R = (A' * A)/2;
array_length = length(A);
eigenvalues = manual_eigenvalue_decomposition(R, array_length);
disp('Eigenvalues:');
disp(eigenvalues);

eigenvectors = find_eigenvectors(R, eigenvalues);
disp('Eigenvector Matrix:');
disp(eigenvectors);

% Manual Eigenvalue Decomposition Function
function eigenvalues = manual_eigenvalue_decomposition(A, n)
eigenvalues = zeros(n, 1); % Initialize eigenvalues as a column vector
for i = 1:n
% Start with a random vector
v = randn(n, 1);

% Power iteration to find the eigenvector corresponding to the largest eigenvalue
for j = 1:10 % Iteration count (power iteration steps)
v = A * v; % Multiply by matrix A
v = v / norm(v); % Normalize the vector
end

% Eigenvalue is the Rayleigh quotient
eigenvalues(i) = (v' * A * v) / (v' * v);

% Deflate the matrix to find the next eigenvector
A = A - eigenvalues(i) * (v * v');
end
end

function eigenvectors = find_eigenvectors(A, eigenvalues)
n = size(A, 1); % Get the size of the matrix A
num_eigenvalues = length(eigenvalues); % Get the number of eigenvalues
eigenvectors = zeros(n, num_eigenvalues); % Initialize eigenvectors matrix

for i = 1:num_eigenvalues
lambda = eigenvalues(i); % Take the eigenvalue

% Solve (A - lambda * I) * v = 0
eig_matrix = A - lambda * eye(n); % (A - lambda * I)

% Find the null space (eigenvector corresponding to the eigenvalue)
v = null(eig_matrix);

% If there are multiple eigenvectors, select the first one
if size(v, 2) > 1
v = v(:, 1);
end

% Normalize the eigenvector
eigenvectors(:, i) = v / norm(v);
end
end


Output 

Eigenvalues:
    2.5000
   -0.0000

Eigenvector Matrix:
    0.4472   -0.8944
    0.8944    0.4472

 

Conclusion

The eigenvalues change, while the eigenvectors remain the same when scaling the input matrix for eigenvalue decomposition.


Copy the MATLAB Code above from here


Further Reading

[1] Singular Value Decomposition in Multi-Antenna Communication

People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *

Popular Posts

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...(MATLAB Code + Simulator)

Bit Error Rate (BER) & SNR Guide Analyze communication system performance with our interactive simulators and MATLAB tools. ๐Ÿ“˜ Theory ๐Ÿงฎ Simulators ๐Ÿ’ป MATLAB Code ๐Ÿ“š Resources BER Definition SNR Formula BER Calculator MATLAB Comparison ๐Ÿ“‚ Explore M-ary QAM, PSK, and QPSK Topics ▼ ๐Ÿงฎ Constellation Simulator: M-ary QAM ๐Ÿงฎ Constellation Simulator: M-ary PSK ๐Ÿงฎ BER calculation for ASK, FSK, and PSK ๐Ÿงฎ Approaches to BER vs SNR What is Bit Error Rate (BER)? The BER indicates how many corrupted bits are received compared to the total number of bits sent. It is the primary figure of merit for a...

Online Simulator for ASK, FSK, and PSK

Try our new Digital Signal Processing Simulator!   •   Interactive ASK, FSK, and BPSK tools updated for 2025. Start Now Interactive Modulation Simulators Visualize binary modulation techniques (ASK, FSK, BPSK) in real-time with adjustable carrier and sampling parameters. ๐Ÿ“ก ASK Simulator ๐Ÿ“ถ FSK Simulator ๐ŸŽš️ BPSK Simulator ๐Ÿ“š More Topics ASK Modulator FSK Modulator BPSK Modulator More Topics Simulator for Binary ASK Modulation Digital Message Bits Carrier Freq (Hz) Sampling Rate (...

Constellation Diagrams of ASK, PSK, and FSK (with MATLAB Code + Simulator)

Constellation Diagrams: ASK, FSK, and PSK Comprehensive guide to signal space representation, including interactive simulators and MATLAB implementations. ๐Ÿ“˜ Overview ๐Ÿงฎ Simulator ⚖️ Theory ๐Ÿ“š Resources Definitions Constellation Tool Key Points MATLAB Code ๐Ÿ“‚ Other Topics: M-ary PSK & QAM Diagrams ▼ ๐Ÿงฎ Simulator for M-ary PSK Constellation ๐Ÿงฎ Simulator for M-ary QAM Constellation BASK (Binary ASK) Modulation Transmits one of two signals: 0 or -√Eb, where Eb​ is the energy per bit. These signals represent binary 0 and 1. BFSK (Binary FSK) Modulation Transmits one ...

Online Simulator for Frequency Modulatiuon

Frequency Modulation Message Frequency (Hz): Generate Message Carrier Frequency (Hz): Generate Carrier Message Signal Amplitude: Carrier Signal Amplitude: Generate Modulated Signal Demodulate Further Reading  Amplitude Modulation Simulator Phase Modulation Simulator  Explore DSP Simulations   Online Signal Processing Simulations Home Page >

Time / Frequency Separation for Orthogonality

๐Ÿ“˜ Theory ๐Ÿ“ Derivation ๐Ÿ“Š Examples ๐Ÿงฎ Simulator Try the Interactive BFSK / FM Simulator Visualize modulation and understand concepts faster. Launch BFSK Simulator Launch FM Simulator BFSK Orthogonality Simulator Derivation of Frequency Separation for Orthogonality Step 1: Define BFSK Signals Copy s₁(t) = √(2E b /T) cos(2ฯ€f₁t) Copy s₂(t) = √(2E b /T) cos(2ฯ€f₂t) Defined over: 0 ≤ t ≤ T For orthogonality: Copy ∫₀แต€ s₁(t)s₂(t) dt = 0 Step 2: Remove Constants Copy ∫₀แต€ cos(2ฯ€f₁t) cos(2ฯ€f₂t) dt = 0 Step 3: Use Trigonometric Identity Copy cos A cos B = ½ [ cos(A − B) + cos(A + B) ] Applying identity: Copy ½ ∫₀แต€ [ cos(2ฯ€(f₁ − f₂)t) + cos(2ฯ€(f₁ + f₂)t) ] dt Ste...

UGC NET Electronic Science Previous Year Question Papers

Home / Engineering & Other Exams / UGC NET 2022 PYQ ๐Ÿ“ฅ Download UGC NET Electronics PDFs Complete collection of previous year question papers, answer keys and explanations for Subject Code 88. Start Downloading UGC-NET (Electronics Science, Subject code: 88) Subject_Code : 88; Department : Electronic Science; ๐Ÿ“‚ View All Question Papers UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2025] with full explanation UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2024] UGC Net Paper 1 With Answer Key Download Pdf [Sep 2024] with full explanation UGC Net Electronic Science Question Paper With Answer Key Download Pdf [Aug 2024] with full explanation UGC Net Paper 1 With Answer Key Download...

FM Modulation Online Simulator

Frequency Modulation Simulator Message Frequency (fm): Hz Carrier Frequency (fc): Hz Carrier Amplitude (Ac): Modulation Index (ฮฒ): Frequency deviation ฮ”f = ฮฒ × fm Online Signal Processing Simulations Home Page >

Comparisons among ASK, PSK, and FSK (with MATLAB + Simulator)

๐Ÿ“˜ Comparisons among ASK, FSK, and PSK ๐Ÿงฎ Online Simulator for calculating Bandwidth of ASK, FSK, and PSK ๐Ÿงฎ MATLAB Code for BER vs. SNR Analysis of ASK, FSK, and PSK ๐Ÿ“š Further Reading ๐Ÿ“‚ View Other Topics on Comparisons among ASK, PSK, and FSK ... ๐Ÿงฎ Comparisons of Noise Sensitivity, Bandwidth, Complexity, etc. ๐Ÿงฎ MATLAB Code for Constellation Diagrams of ASK, FSK, and PSK ๐Ÿงฎ Online Simulator for ASK, FSK, and PSK Generation ๐Ÿงฎ Online Simulator for ASK, FSK, and PSK Constellation ๐Ÿงฎ Some Questions and Answers Modulation ASK, FSK & PSK Constellation MATLAB Simulink MATLAB Code Comparisons among ASK, PSK, and FSK    Comparisons among ASK, PSK, and FSK Comparison among ASK, FSK, and PSK Parameters ASK FSK PSK Variable Characteristics Amplitude Frequency ...