%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                            Michael Pokojovy                             % 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rho = 19300;
E   = 80E9;

c = sqrt(E/rho);

L = 0.3;

T = 6*L/c;

U0 = @(x) L/2 - abs(x - L/2);
u0 = @(x) (-1).^floor(x/L).*U0(x - floor(x/L)*L);

u = @(t, x) 1/2*(u0(x - c*t) + u0(x + c*t));

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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('L\"osung des ARWP der gezupften Saite', 'interpreter', 'latex');
set(t, 'FontSize', 16);

M = 50;
N = 50;

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

U = u(T, X);

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('L\"osung des ARWP der gezupften Saite', '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 = u(tlattice(k), xlattice);
    plot(xlattice, ulattice);
    
    axis([0 L -L/2 L/2]);
    
    h = title(['$t = $ ' num2str(tlattice(k)) ' [s]'], 'interpreter', 'latex');
    set(h, 'FontSize', 16);
    
    xlabel('x');
    ylabel('u(t, x)');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
