Code covered by the BSD License

# 3D Plotter for Infinite Potential Well

### Sean Hatch (view profile)

plots a user-specified wavefunction in an infinite potential well of user-specified size.

particleBox3D(L,n,dl,sizefactor)
%*************************************************************************
%function particleBox3D(L,n,dl,sizefactor) is a simple function which plots
%the square of the absolute value of a wavefunction in a 3D infinite potential well.
%The value of the abs(psi)^2 at a point in space determines its color and
%point-size in the MATLAB plot.
%
%
%Arguments:
%L is a vector of length 3 containing the dimensions of the potential well
%in the x, y, and z directions.
%
%n is a vector of lengh 3 which contains nx,ny,and nz for the system.
%
%dl is a vector of length 3 which contains the step for calculation and
%plotting in the x,y, and z directions.
%
%sizefactor sets the size of the points in the final plot.  You may have to
%toy with this a bit.
%
%
%Example:
%energyBoxPlot([10e-9,10e-9,10e-9],[2,2,1],[50e-11,50e-11,50e-11],100)
%
%par
%To Do:
%-calculate dl automatically (erroneous choice of dl can lock up your
%system)
%-modulate point size based on L and or dl.
%
%10/25/09
%**************************************************************************

function particleBox3D(L,n,dl,sizefactor)

%create mesh grid etc.
x1= 0:dl(1):L(1)
x2= 0:dl(2):L(2)
x3= 0:dl(3):L(3)

kx = n(1)/L(1);
ky = n(2)/L(2);
kz = n(3)/L(3);

[x,y,z] = meshgrid(x1,x2,x3)

%Calculate wavefunction etc. at each point in the meshgrid.
waveFunction = sin(kx.*pi.*x).*sin(ky.*pi.*y).*sin(kz.*pi.*z)
waveProbability = (abs(waveFunction)).^2

%plot each point where the plotting setting are dynamic for each point.
for xdim = 1:length(x1)
for ydim = 1:length(x2)
for zdim = 1:length(x3)

%use sizefactor to modify size of points in plot
currentVal = waveProbability(xdim,ydim,zdim)*sizefactor;
plot3((length(x1)-xdim)*dl(1),(length(x2)-ydim)*dl(2),(length(x3)-zdim)*dl(3),'.','MarkerSize',(currentVal +.1),'MarkerEdgeColor',[1,waveProbability(xdim,ydim,zdim),0])
hold on

end
end
end

%some labeling
xlabel('x (m)');
ylabel('y (m)');
zlabel('z (m)');
title('|\psi (x,y,z)|^2 for A = 1')