%% Spectrum Decomposition for Quantum State

clc; clear all; close all;

%
%% Quantum Operator

x = [0 1; 1 0 ];

%
%% Eigen vector & Eigen Value

[v,d] = eig(x);

lambda = diag(d);

check1 = x*v(:,1)-lambda(1,1)*v(:,1);
check2 = x*v(:,2)-lambda(2,1)*v(:,2);

lambda1 = lambda(1,1);
lambda2 = lambda(2,1);
ket1 = v(:,1);
ket2 = v(:,2);

%
%% Specturm Decomposition

xx = ket1*ket1'.*lambda1+ket2*ket2'.*lambda2;