% PHYS3900 Simulation - Infinite Potential Well
% Non-variable constants
h = 1; % Defined arbitrarily for plotting

% Constants (To be variable in the javascript version as an arbitrary
% slider)
n = 5; % Ranged from n = 1 to n = 5
L = 2; % Ranged from L = 0.5 to L = 5
m = 2; % Ranged from m = 0.1 to m = 10

% Normalisation constant
A = sqrt(2/L);

% Plot wavefunction and probability density
x = linspace(-L/2,L/2,10000);
wavefcn = A*sin((n*pi*x)/L);
probdensity = abs(wavefcn).^2;
plot(x,wavefcn)
hold on;
plot(x,probdensity)
hold on;

% Calculate energy and display as a line on the grid
E = (n^2*h^2)/(8*m*L^2);
disp(E)
plot(x, E*ones(size(x)),'--')
hold on;

% Display appropriate labels on graph
set(gca, 'XTick', [-L/2 0 L/2]);
set(gca, 'XTickLabel',...
    {'-L/2', '0', 'L/2'},...
    'TickLabelInterpreter', 'latex');
xlabel('Well Length (L)',...
    'Interpreter', 'latex');

set(gca, 'YTick', [-sqrt(2/L) 0 sqrt(2/L)]);
set(gca, 'YTickLabel',...
    {'$\sqrt(2/L)$', '0', '$\sqrt(2/L)$'},...
    'TickLabelInterpreter', 'latex');

legend({'$\Psi(x)$','$|\Psi(x)|^{2}$','Particle Energy'},...
    'Location','southwest','Interpreter','latex')
