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...

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 ...

DFTs-OFDM vs OFDM: Why DFT-Spread OFDM Reduces PAPR Effectively (with MATLAB Code)

DFT-spread OFDM (DFTs-OFDM) has lower Peak-to-Average Power Ratio (PAPR) because it "spreads" the data in the frequency domain before applying IFFT, making the time-domain signal behave more like a single-carrier signal rather than a multi-carrier one like OFDM. Deeper Explanation: Aspect OFDM DFTs-OFDM Signal Type Multi-carrier Single-carrier-like Process IFFT of QAM directly QAM → DFT → IFFT PAPR Level High (due to many carriers adding up constructively) Low (less fluctuation in amplitude) Why PAPR is High Subcarriers can add in phase, causing spikes DFT "pre-spreads" data, smoothing it Used in Wi-Fi, LTE downlink LTE uplink (as SC-FDMA) In OFDM, all subcarriers can...

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 (...

Power Distribution in Amplitude Modulation (AM)

Power Distribution In practice, the AM wave s(t) is a voltage or current signal. In either case, the average power delivered to a 1-ohm load resistor by s(t) is comprised of three components: Carrier power = (1/2) A c 2 Upper side-frequency power = (1/8)μ 2 A c 2 Lower side-frequency power = (1/8)μ 2 A c 2 The ratio of the total sideband power to the total power in the modulated wave is therefore equal to μ 2 / (2 + μ 2 ), which depends only on the modulation factor μ. If μ = 1, that is, 100% modulation is used, the total power in the two side-frequencies of the resulting AM wave is only one-third of the total power in the modulated wave. A major topic in Amplitude Modula...

Filter Bank Multicarrier (FBMC)

Filter Bank Multicarrier (FBMC) Filter Bank Multicarrier (FBMC) is an advanced multicarrier modulation technique designed to overcome the spectral inefficiencies and interference issues of OFDM. Motivation: Limitations of OFDM In an OFDM system , the transmitter uses an Inverse Fast Fourier Transform (IFFT) and the receiver uses a Fast Fourier Transform (FFT) to process multiple subcarriers. Each OFDM symbol occupies a duration denoted by T sym . OFDM is a multicarrier modulation technique where a high data-rate stream is divided into multiple parallel low data-rate streams. To mitigate inter-symbol interference (ISI) caused by multipath fading, the total bandwidth B is divided into N narrow sub-bands. However, a major drawback of OFDM is that the subcarrier filters generated by the IFFT/FFT process have poor spectral cont...

OFDM vs SC-OFDM

  The main difference between OFDM and SC-OFDM is that SC-OFDM transmits the signal using a single carrier, while OFDM uses multiple subcarriers. However, in SC-OFDM, the signal is generated with different sub-bands, but it is transmitted through a single carrier (more technically, through a wideband carrier signal). Block Diagram of OFDM: Data → Modulation → Serial-to-Parallel → IFFT → Add CP → Transmit Received Signal → Remove CP → FFT → Parallel-to-Serial → Demodulation → Data Block Diagram of SC-OFDM: Data → Modulation → DFT → IFFT → Add CP → Transmit Received Signal → Remove CP → FFT → Demodulation → Data    In the case of OFDM, the input modulated data is converted from a serial stream to parallel streams, and different subcarriers are assigned to each chunk. Then, IFFT is applied to these chunks, and a cyclic prefix is added to each one. Each chunk is technically referred to as an OFDM symbol . Unlike OFDM, SC-OFDM does not perform serial-to-parallel conversion o...