In [1]:

    # ELECTRON IN CUBE = visualization of our solutions of Schr.eq = function F(x,y,z)
    # (full justification of Schrodinger equation + detailed comments -> EM lectures
    # (here: visualization of the solutinon = characteristic function F(x,y,z)

In [2]:

    import numpy as np
    import matplotlib.pyplot as plt

In [3]:

    from numpy import pi

In [4]:

    # Prepare functions
    # (here: we have selected cos-functions
    # (for sin-functions it would be completele analogous
    # (only the allowed values of Nx,Ny,Nz woud be different: 2,4,6...

In [5]:

    def F1(x): return A*np.cos(pi*Nx/L * x)
    def F2(y): return A*np.cos(pi*Ny/L * y)
    def F3(z): return A*np.cos(pi*Nz/L * z)

In [6]:

    def F(x,y,z): return F1(x)*F2(y)*F3(z)

In [7]:

    # Prepare X,Y variables
    # (note: for plotting of F(x,y) we have to use meshgrid

In [8]:

    X = np.linspace(-2.5,2.5,501, endpoint=True)
    Y = np.linspace(-2.5,2.5,501, endpoint=True)

In [9]:

    Xm,Ym = np.meshgrid(X,Y)

In [10]:

    # Visualization of several possible solutions
    # 1) We display values of |F(x,y,z)|**2 = probability of finding eln at x,y,z
    #    (strictly speaking: probability of finding eln in volume element x,y,z
    #    (here: size of the volume element is given by the grid defined above
    # 2) Moreover, for simplicity we display values of |F(x,y,0)|**2
    #    (i.e. we display probability in the middle of the cube, at z=0
    #    (this can be changed when calling function: F(x,y,0) -> F(x,y,1)

In [11]:

    # Example of solution #1: Nx = Ny = Nz = 1

In [12]:

    A = 1; L = 5; Nx = Ny = Nz = 1

In [13]:

    Z = np.abs(F(Xm,Ym,0))**2

In [14]:

    plt.gca().set_aspect('equal')
    plt.contourf(Xm,Ym,Z, 40, cmap='coolwarm')
    plt.colorbar()
    plt.show()

In [15]:

    # Example of solution #2: Nx = 3, Ny = Nz = 1

In [16]:

    A = 1; L = 5; Nx = 3; Ny = Nz = 1

In [17]:

    Z = np.abs(F(Xm,Ym,0))**2

In [18]:

    plt.gca().set_aspect('equal')
    plt.contourf(Xm,Ym,Z, 40, cmap='coolwarm')
    plt.colorbar()
    plt.show()

In [19]:

    # Example of solution #3: Nx = Ny = Nz = 3

In [20]:

    A = 1; L = 5; Nx = Ny = Nz = 3

In [21]:

    Z = np.abs(F(Xm,Ym,0))**2

In [22]:

    plt.gca().set_aspect('equal')
    plt.contourf(Xm,Ym,Z, 40, cmap='coolwarm')
    plt.colorbar()
    plt.show()

In [23]:

    # Example of arbitrary solution: Nx,Ny,Nz may be defined by user
    # (note: allowed values for Nx,Ny,Nz = 1,3,5...

In [24]:

    A = 1; L = 5; Nx = 1; Ny = 5; Nz = 1

In [25]:

    Z = np.abs(F(Xm,Ym,0))**2

In [26]:

    plt.gca().set_aspect('equal')
    plt.contourf(Xm,Ym,Z, 40, cmap='coolwarm')
    plt.colorbar()
    plt.show()