%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                            Michael Pokojovy                             % 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rho = 7800;
E   = 210E9;

c = sqrt(E/rho);
g = 9.81;

L = 0.5;

T = 6*L/c;

lambda = @(n) (pi*n/L)^2;
phi = @(n, x) sqrt(2/L)*sin(pi*n/L*x);

un = @(n, t) -(1/L)^2*L^3*g*2^(1/2)*(1/L)^(1/2)*(-1+(-1)^n)*(cos(c*pi*n*t/L)-1)/c^2/pi^3/n^3;

K = 30;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1);

set(gcf, 'PaperUnits', 'centimeters');
xSize = 20; ySize = 10;
xLeft = (21 - xSize)/2; yTop = (30 - ySize)/2;
set(gcf,'PaperPosition', [xLeft yTop xSize ySize]);
set(gcf,'Position',[0 0 xSize*50 ySize*50]);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hold on;

t = title('Stahlsaite im Gravitationsfeld der Erde', 'interpreter', 'latex');
set(t, 'FontSize', 16);

M = 50;
N = 50;

[X, T] = meshgrid(linspace(0, L, M), linspace(0, T, N));

U = zeros(size(X));

for n = 1:K
    U = U + un(n, T).*phi(n, X);
end

colormap hot;
surf(X, T, U);

view([39 38]);

grid on;

xlabel('x [m]');
ylabel('t [s]');
zlabel('u(t, x) [m]');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(2);

set(gcf, 'PaperUnits', 'centimeters');
xSize = 20; ySize = 10;
xLeft = (21 - xSize)/2; yTop = (30 - ySize)/2;
set(gcf,'PaperPosition', [xLeft yTop xSize ySize]);
set(gcf,'Position',[0 0 xSize*50 ySize*50]);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hold on;

t = title('Stahlsaite im Gravitationsfeld der Erde', 'interpreter', 'latex');
set(t, 'FontSize', 16);

T = 6*L/c;

tlattice = linspace(0, T, 9);
xlattice = linspace(0, L, 100);

k = 0;
for i = 1:3
for j = 1:3
    k = k + 1;
    subplot(3, 3, k);
    
    ulattice = zeros(size(xlattice));
    for n = 1:K
    	ulattice = ulattice + un(n, tlattice(k)).*phi(n, xlattice);
    end
    
    plot(xlattice, ulattice);
    
    axis([0 L -9.5E-8 9.5E-8]);
    
    h = title(['$t = $ ' num2str(tlattice(k)) ' [s]'], 'interpreter', 'latex');
    set(h, 'FontSize', 16);
    
    xlabel('x');
    ylabel('u(t, x)');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
