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







Admin & Author: Salim

s

  Website: www.salimwireless.com
  Interests: Signal Processing, Telecommunication, 5G Technology, Present & Future Wireless Technologies, Digital Signal Processing, Computer Networks, Millimeter Wave Band Channel, Web Development
  Seeking an opportunity in the Teaching or Electronics & Telecommunication domains.
  Possess M.Tech in Electronic Communication Systems.


Contact Us

Name

Email *

Message *

Popular Posts

Simulation of ASK, FSK, and PSK using MATLAB Simulink

📘 Overview 🧮 How to use MATLAB Simulink 🧮 Simulation of ASK using MATLAB Simulink 🧮 Simulation of FSK using MATLAB Simulink 🧮 Simulation of PSK using MATLAB Simulink 🧮 Simulator for ASK, FSK, and PSK 🧮 Digital Signal Processing Simulator 📚 Further Reading ASK, FSK & PSK HomePage MATLAB Simulation Simulation of Amplitude Shift Keying (ASK) using MATLAB Simulink      In Simulink, we pick different components/elements from MATLAB Simulink Library. Then we connect the components and perform a particular operation.  Result A sine wave source, a pulse generator, a product block, a mux, and a scope are shown in the diagram above. The pulse generator generates the '1' and '0' bit sequences. Sine wave sources produce a specific amplitude and frequency. The scope displays the modulated signal as well as the original bit sequence created by the pulse generator. Mux is a tool for displaying b...

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...

📘 Overview of BER and SNR 🧮 Online Simulator for BER calculation of m-ary QAM and m-ary PSK 🧮 MATLAB Code for BER calculation of M-ary QAM, M-ary PSK, QPSK, BPSK, ... 📚 Further Reading 📂 View Other Topics on M-ary QAM, M-ary PSK, QPSK ... 🧮 Online Simulator for Constellation Diagram of m-ary QAM 🧮 Online Simulator for Constellation Diagram of m-ary PSK 🧮 MATLAB Code for BER calculation of ASK, FSK, and PSK 🧮 MATLAB Code for BER calculation of Alamouti Scheme 🧮 Different approaches to calculate BER vs SNR What is Bit Error Rate (BER)? The abbreviation BER stands for bit error rate, which indicates how many corrupted bits are received (after the demodulation process) compared to the total number of bits sent in a communication process. It is defined as,  In mathematics, BER = (number of bits received in error / total number of transmitted bits)  On the other hand, SNR ...

MATLAB Code for ASK, FSK, and PSK

📘 Overview & Theory 🧮 MATLAB Code for ASK 🧮 MATLAB Code for FSK 🧮 MATLAB Code for PSK 🧮 Simulator for binary ASK, FSK, and PSK Modulations 📚 Further Reading ASK, FSK & PSK HomePage MATLAB Code MATLAB Code for ASK Modulation and Demodulation % The code is written by SalimWireless.Com % Clear previous data and plots clc; clear all; close all; % Parameters Tb = 1; % Bit duration (s) fc = 10; % Carrier frequency (Hz) N_bits = 10; % Number of bits Fs = 100 * fc; % Sampling frequency (ensure at least 2*fc, more for better representation) Ts = 1/Fs; % Sampling interval samples_per_bit = Fs * Tb; % Number of samples per bit duration % Generate random binary data rng(10); % Set random seed for reproducibility binary_data = randi([0, 1], 1, N_bits); % Generate random binary data (0 or 1) % Initialize arrays for continuous signals t_overall = 0:Ts:(N_bits...

Constellation Diagrams of ASK, PSK, and FSK

📘 Overview of Energy per Bit (Eb / N0) 🧮 Online Simulator for constellation diagrams of ASK, FSK, and PSK 🧮 Theory behind Constellation Diagrams of ASK, FSK, and PSK 🧮 MATLAB Codes for Constellation Diagrams of ASK, FSK, and PSK 📚 Further Reading 📂 Other Topics on Constellation Diagrams of ASK, PSK, and FSK ... 🧮 Simulator for constellation diagrams of m-ary PSK 🧮 Simulator for constellation diagrams of m-ary QAM 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 of two signals: +√Eb​ ( On the y-axis, the phase shift of 90 degrees with respect to the x-axis, which is also termed phase offset ) or √Eb (on x-axis), where Eb​ is the energy per bit. These signals represent binary 0 and 1.  BPSK (Binary PSK) Modulation: Transmits one of two signals...

Theoretical vs. simulated BER vs. SNR for ASK, FSK, and PSK

📘 Overview 🧮 Simulator for calculating BER 🧮 MATLAB Codes for calculating theoretical BER 🧮 MATLAB Codes for calculating simulated BER 📚 Further Reading BER vs. SNR denotes how many bits in error are received for a given signal-to-noise ratio, typically measured in dB. Common noise types in wireless systems: 1. Additive White Gaussian Noise (AWGN) 2. Rayleigh Fading AWGN adds random noise; Rayleigh fading attenuates the signal variably. A good SNR helps reduce these effects. Simulator for calculating BER vs SNR for binary ASK, FSK, and PSK Calculate BER for Binary ASK Modulation Enter SNR (dB): Calculate BER Calculate BER for Binary FSK Modulation Enter SNR (dB): Calculate BER Calculate BER for Binary PSK Modulation Enter SNR (dB): Calculate BER BER vs. SNR Curves MATLAB Code for Theoretical BER % The code is written by SalimWireless.Com clc; clear; close all; % SNR v...

Comparisons among ASK, PSK, and FSK | And the definitions of each

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

Online Simulator for ASK, FSK, and PSK

Try our new Digital Signal Processing Simulator!   Start Simulator for binary ASK Modulation Message Bits (e.g. 1,0,1,0) Carrier Frequency (Hz) Sampling Frequency (Hz) Run Simulation Simulator for binary FSK Modulation Input Bits (e.g. 1,0,1,0) Freq for '1' (Hz) Freq for '0' (Hz) Sampling Rate (Hz) Visualize FSK Signal Simulator for BPSK Modulation ...

MATLAB Code for Constellation Diagram of QAM configurations such as 4, 8, 16, 32, 64, 128, and 256-QAM

📘 Overview of QAM 🧮 MATLAB Code for m-ary QAM (4-QAM, 16-QAM, 32-QAM, ...) 🧮 Online Simulator for M-ary QAM Constellations (4-QAM, 16-QAM, 64-QAM, ...) 📚 Further Reading 📂 Other Topics on Constellation Diagrams of QAM configurations ... 🧮 MATLAB Code for 4-QAM 🧮 MATLAB Code for 16-QAM 🧮 MATLAB Code for m-ary QAM (4-QAM, 16-QAM, 32-QAM, ...) 🧮 Simulator for constellation diagrams of m-ary PSK 🧮 Simulator for constellation diagrams of m-ary QAM 🧮 Overview of Energy per Bit (Eb / N0) 🧮 Online Simulator for constellation diagrams of ASK, FSK, and PSK 🧮 Theory behind Constellation Diagrams of ASK, FSK, and PSK 🧮 MATLAB Codes for Constellation Diagrams of ASK, FSK, and PSK   One of the best-performing modulation techniques is QAM [↗] . Here, we modulate the symbols by varying the carrier signal's amplitude and phase in response to the vari...