clc
clear all
syms k
K_2d = [1 k;
        k 1];
K_3d = [1 k k;
        k 1 k; 
        k k 1];
%% choose 2d or 3d (uncomment line 10 or 11)
% K = K_2d;
K = K_3d;

M = size(K,1);
% centering formula
T = @(i,j) K(i,j) - 1/M * sum(K(i,:)) - 1/M * sum(K(:,j)) + 1/M^2 * sum(sum(K));
K_centered = K;
for i = 1:1:size(K,1)
    for j = 1:1:size(K,2)
        K_centered(i,j) = T(i,j);
    end
end
[V,D] = eig(K_centered);
disp('Centered Gram matrix:')
disp(K_centered)
disp('Eigenvectors (in columns):')
disp(V)