clear all;
clc;

n        = 3;

%  ------- Case 1: dim Kernel = 1  --------
A      = [2 0 -1; 0 2 1; -1 -1 2]
e_vals = eig(A)

lambda = 2
M      = A - lambda*eye(3)

dim_R  = rank(M)
dim_K  = n - dim_R

span_K = null(M)
span_R = orth(M)

% ------- Jordan Canonical Form  --------
[X,J]  = jordan(A)


%  ------- Case 2: dim Kernel = 2  --------
% A      = [1 1 0; -1 3 0; -1 1 2]
% e_vals = eig(A)
% 
% lambda = 2;
% M      = A - lambda*eye(3)
% 
% dim_R  = rank(M)
% dim_K  = n - dim_R
% 
% span_K = null(M)
% span_R = orth(M)
% [X,J] = jordan(A)