image thumbnail

3D Plotter for Infinite Potential Well



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

%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.
%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.
%To Do:
%-calculate dl automatically (erroneous choice of dl can lock up your
%-modulate point size based on L and or dl.  

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

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

Contact us