close all
clear all
frequency = 3e9;
lambda = 3e8/frequency;
antenna_spacing = [lambda/4,lambda/2,lambda*2/3,lambda];
x_number_total = floor(2*3*lambda./antenna_spacing); y_number_total = floor(2*3*lambda./antenna_spacing);z_number = 5;

for z_iter = 1:length(antenna_spacing)
    x_number = x_number_total(z_iter);
    y_number = y_number_total(z_iter);
axis = cell(x_number*y_number*z_number,1);
for i = 1:x_number
    for j = 1:y_number
        for k = 1:z_number
            axis{(i-1)*y_number*z_number+(j-1)*z_number+k} = [i*antenna_spacing(z_iter),j*antenna_spacing(z_iter),k*lambda/2];
        end
    end
end

[kernel_matrix] = kernel_calculate(frequency,axis,"ball");

eigen_value = eig(kernel_matrix);
eigen_value = flip(eigen_value);

    eigen_value = eigen_value/eigen_value(1);


x = 1:20:200*z_number;

if(z_iter==1)
    plot(x,eigen_value(1:20:200*z_number),'-s','color','red','Linewidth',1.5,'markersize',4)
elseif(z_iter==2)
    hold on
    plot(x(1:length(eigen_value(1:20:end))),eigen_value(1:20:end),'-o','color','m','Linewidth',1.5,'markersize',4)
elseif(z_iter==3)
    hold on
    plot(x(1:length(eigen_value(1:20:end))),eigen_value(1:20:end),'-+','color','blue','Linewidth',1.5,'markersize',4)
% elseif(z_iter==4)
%     hold on
%     plot(x(1:length(eigen_value(1:20:end))),eigen_value(1:20:end),'-^','color','blue','Linewidth',1.5,'markersize',4)
end
end

for z_iter = 1:length(antenna_spacing)
    x_number = x_number_total(z_iter);
    y_number = y_number_total(z_iter);
axis = cell(x_number*y_number*z_number,1);
for i = 1:x_number
    for j = 1:y_number
        for k = 1:z_number
            axis{(i-1)*y_number*z_number+(j-1)*z_number+k} = [i*antenna_spacing(z_iter),j*antenna_spacing(z_iter),k*lambda/2];
        end
    end
end

[kernel_matrix] = kernel_calculate(frequency,axis,"sphere");

eigen_value = eig(kernel_matrix);
eigen_value = flip(eigen_value);
eigen_value = eigen_value/eigen_value(1);

x = 1:20:200*z_number;

if(z_iter==1)
    plot(x,eigen_value(1:20:200*z_number),'--s','color','red','Linewidth',1.5,'markersize',4)
elseif(z_iter==2)
    hold on
    plot(x(1:length(eigen_value(1:20:end))),eigen_value(1:20:end),'--o','color','m','Linewidth',1.5,'markersize',4)
elseif(z_iter==3)
    hold on
    plot(x(1:length(eigen_value(1:20:end))),eigen_value(1:20:end),'--+','color','blue','Linewidth',1.5,'markersize',4)
% elseif(z_iter==4)
%     hold on
%     plot(x(1:length(eigen_value(1:20:end))),eigen_value(1:20:end),'--^','color','blue','Linewidth',1.5,'markersize',4)
end
end
grid on
xlabel('Eigenvalue Index','Interpreter','latex','FontSize',14);
ylabel('Eigenvalue','Interpreter','latex','FontSize',14);
legend('ball $\lambda/4$','ball $\lambda/2$','ball $2\lambda/3$','sphere surface $\lambda/4$','sphere surface $\lambda/2$','sphere surface $2\lambda/3$','Interpreter','latex')