Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Particle in a Box

Wave Function Plot

Ψ = (2/L)^(1/2) * sin(nπx/L)

Where, n = 1, 2, 3………
Code to plot on MATLAB ~:
prompt = 'What is the length of box? ';
L = input(prompt);
x=linspace(0,L);
prompt = 'What do you want your starting n value to be?';
u = input(prompt);
prompt = 'What do you want your ending n value to be?';
t = input(prompt);
figure;
for i=u:t
psi =sin(i*pi*x);
plot(x,psi,'color', rand(1,3),'LineWidth', 2,'DisplayName',sprintf('n
= %d',i));
hold on;
legend('show');
end
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
xlabel ('0 < X < L');
ylabel ('\psi = Wave function')
title('\psi vs x Plot for Different n')
grid on

Comment on code Here we can draw graphs for


– more than
3 values of n too on the same axes and plot, by giving the
desired starting and ending value of n. for e.g from n=4
to n=11
But lets take n=1 to n= 3 to have neat view and better
understanding.
Input
What is the length of box?
1
What do you want your starting n value to be?
1
What do you want your ending n value to be?
3
Probability Distribution Plot
|Ψ |^2= (2/L)* (sin(nπx/L))^2

Code to plot on MATLAB ~:

prompt = 'What is the length of box? ';


L = input(prompt);
x=linspace(0,L);
prompt = 'What do you want your starting n value to be?';
u = input(prompt);
prompt = 'What do you want your ending n value to be?';
t = input(prompt);
figure;
M = '|psi|.^2';
for i=u:t
M = (sin(i*pi*x)).^2;
plot(x,M,'color', rand(1,3),'LineWidth', 2,'DisplayName',sprintf('n =
%d',i));
hold on
legend('show');
end
ax = gca;
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin';
xlabel ('0 < X < L');
ylabel ('|\psi|.^2')
title('Probability distribution vs different n')
grid on

Comment on code Here we can draw graphs for


– more than
3 values of n too on the same axes and plot, by giving the
desired starting and ending value of n. for e.g from n=4
to n=11
But lets take n=1 to n= 3 to have neat view and better
understanding.

Input
What is the length of box?
1
What do you want your starting n value to be?
1
What do you want your ending n value to be?
3

You might also like