Schrodinger_App/SchrodingerApp.py
def eval_eigenvalues():
    '''
    This method of evaluating eigenvalues is called Numerov method. The method used 
    below can be found in N. Zettili -- Quantum Mechanics.
    '''
    potential = schro_var()
    psi = np.zeros(N)
    psi_final = []
    eigenEnergies = np.zeros(Nmax)
    psi_left, psi_right = 1.0e-6, 0.0
    psi[0], psi[1] = psi_left, psi_left + 1.0e-6
    ElowerLimit = 0.0
    EupperLimit = 10.0
    h0 = (xmax - xmin) / N
    xRange = np.arange(xmin, xmax, h0)
    Endsign = -1
    terminal = 0
    for nQuantum in range(Nmax):
        Limits_are_defined = False
        while Limits_are_defined is False:
            nodes_plus = 0
            Etrial = EupperLimit
            terminal += 1
            if terminal >= 1000:
                Text = f"the iteration didn't converge. please use different xmin and xmax or change the potential"
                my_canvas.bind(show_text)
                obj_id = my_canvas.create_text(20, 30, text=Text)
                break
            for i in range(2, N):
                Ksquare = 2.0 * (Etrial - V(xRange[i]))
                psi[i] = (
                    2.0
                    * psi[i - 1]
                    * (1.0 - 5.0 * h0 * h0 * Ksquare / 12.0)
                    / (1.0 + (h0 * h0 * Ksquare / 12.0))
                    - psi[i - 2]
                )
                if psi[i] * psi[i - 1] < 0:
                    nodes_plus += 1
            if EupperLimit < ElowerLimit:
                EupperLimit = np.max([2 * EupperLimit, -2.0 * EupperLimit])
            if nodes_plus > nQuantum + 1:
                EupperLimit *= 0.7
            elif nodes_plus < nQuantum + 1:
                EupperLimit *= 2.0
            else:
                Limits_are_defined = True
        Endsign *= -1
        while EupperLimit - ElowerLimit > epsilon:
            Etrial = (EupperLimit + ElowerLimit) / 2.0
            for i in range(2, N):
                Ksquare = 2.0 * (Etrial - V(xRange[i]))
                psi[i] = (
                    2.0
                    * psi[i - 1]
                    * (1.0 - 5.0 * h0 * h0 * Ksquare / 12.0)
                    / (1.0 + (h0 * h0 * Ksquare / 12))
                    - psi[i - 2]
                )
            if Endsign * psi[-1] > psi_right:
                ElowerLimit = Etrial
            elif Endsign * psi[-1] < psi_right:
                EupperLimit = Etrial
            else:
                exit()

        Etrial = (EupperLimit + ElowerLimit) / 2
        eigenEnergies[nQuantum] = Etrial
        EupperLimit = Etrial
        ElowerLimit = Etrial

        # Normalization
        Integral = 0.0
        for i in range(N):
            Integral += 0.5 * h0 * (psi[i - 1] * psi[i - 1] + psi[i] * psi[i])

        normCoeff = np.sqrt(1.0 / Integral)
        psi_final.append(normCoeff * psi)

    potential = np.zeros(len(xRange))
    potential = [V(xRange[i]) for i in range(len(xRange))]
    # psi_final.append(potential)
    return xRange, psi_final, eigenEnergies

    This method of evaluating eigenvalues is called Numerov method. The method used 
    below can be found in N. Zettili -- Quantum Mechanics.
    
This method of evaluating eigenvalues is called Numerov method. The method used
below can be found in N. Zettili -- Quantum Mechanics.
This method of evaluating eigenvalues is called Numerov method . The method used below can be found in N . Zettili -- Quantum Mechanics .
def eval_eigenvalues():
    potential = schro_var()
    psi = np.zeros(N)
    psi_final = []
    eigenEnergies = np.zeros(Nmax)
    psi_left, psi_right = 1.0e-6, 0.0
    psi[0], psi[1] = psi_left, psi_left + 1.0e-6
    ElowerLimit = 0.0
    EupperLimit = 10.0
    h0 = (xmax - xmin) / N
    xRange = np.arange(xmin, xmax, h0)
    Endsign = -1
    terminal = 0
    for nQuantum in range(Nmax):
        Limits_are_defined = False
        while Limits_are_defined is False:
            nodes_plus = 0
            Etrial = EupperLimit
            terminal += 1
            if terminal >= 1000:
                Text = f"the iteration didn't converge. please use different xmin and xmax or change the potential"
                my_canvas.bind(show_text)
                obj_id = my_canvas.create_text(20, 30, text=Text)
                break
            for i in range(2, N):
                Ksquare = 2.0 * (Etrial - V(xRange[i]))
                psi[i] = (
                    2.0
                    * psi[i - 1]
                    * (1.0 - 5.0 * h0 * h0 * Ksquare / 12.0)
                    / (1.0 + (h0 * h0 * Ksquare / 12.0))
                    - psi[i - 2]
                )
                if psi[i] * psi[i - 1] < 0:
                    nodes_plus += 1
            if EupperLimit < ElowerLimit:
                EupperLimit = np.max([2 * EupperLimit, -2.0 * EupperLimit])
            if nodes_plus > nQuantum + 1:
                EupperLimit *= 0.7
            elif nodes_plus < nQuantum + 1:
                EupperLimit *= 2.0
            else:
                Limits_are_defined = True
        Endsign *= -1
        while EupperLimit - ElowerLimit > epsilon:
            Etrial = (EupperLimit + ElowerLimit) / 2.0
            for i in range(2, N):
                Ksquare = 2.0 * (Etrial - V(xRange[i]))
                psi[i] = (
                    2.0
                    * psi[i - 1]
                    * (1.0 - 5.0 * h0 * h0 * Ksquare / 12.0)
                    / (1.0 + (h0 * h0 * Ksquare / 12))
                    - psi[i - 2]
                )
            if Endsign * psi[-1] > psi_right:
                ElowerLimit = Etrial
            elif Endsign * psi[-1] < psi_right:
                EupperLimit = Etrial
            else:
                exit()
        Etrial = (EupperLimit + ElowerLimit) / 2
        eigenEnergies[nQuantum] = Etrial
        EupperLimit = Etrial
        ElowerLimit = Etrial
        Integral = 0.0
        for i in range(N):
            Integral += 0.5 * h0 * (psi[i - 1] * psi[i - 1] + psi[i] * psi[i])
        normCoeff = np.sqrt(1.0 / Integral)
        psi_final.append(normCoeff * psi)
    potential = np.zeros(len(xRange))
    potential = [V(xRange[i]) for i in range(len(xRange))]
    return xRange, psi_final, eigenEnergies
def eval_eigenvalues ( ) : potential = schro_var ( ) psi = np . zeros ( N ) psi_final = [ ] eigenEnergies = np . zeros ( Nmax ) psi_left , psi_right = 1.0e-6 , 0.0 psi [ 0 ] , psi [ 1 ] = psi_left , psi_left + 1.0e-6 ElowerLimit = 0.0 EupperLimit = 10.0 h0 = ( xmax - xmin ) / N xRange = np . arange ( xmin , xmax , h0 ) Endsign = - 1 terminal = 0 for nQuantum in range ( Nmax ) : Limits_are_defined = False while Limits_are_defined is False : nodes_plus = 0 Etrial = EupperLimit terminal += 1 if terminal >= 1000 : Text = f"the iteration didn't converge. please use different xmin and xmax or change the potential" my_canvas . bind ( show_text ) obj_id = my_canvas . create_text ( 20 , 30 , text = Text ) break for i in range ( 2 , N ) : Ksquare = 2.0 * ( Etrial - V ( xRange [ i ] ) ) psi [ i ] = ( 2.0 * psi [ i - 1 ] * ( 1.0 - 5.0 * h0 * h0 * Ksquare / 12.0 ) / ( 1.0 + ( h0 * h0 * Ksquare / 12.0 ) ) - psi [ i - 2 ] ) if psi [ i ] * psi [ i - 1 ] < 0 : nodes_plus += 1 if EupperLimit < ElowerLimit : EupperLimit = np . max ( [ 2 * EupperLimit , - 2.0 * EupperLimit ] ) if nodes_plus > nQuantum + 1 : EupperLimit *= 0.7 elif nodes_plus < nQuantum + 1 : EupperLimit *= 2.0 else : Limits_are_defined = True Endsign *= - 1 while EupperLimit - ElowerLimit > epsilon : Etrial = ( EupperLimit + ElowerLimit ) / 2.0 for i in range ( 2 , N ) : Ksquare = 2.0 * ( Etrial - V ( xRange [ i ] ) ) psi [ i ] = ( 2.0 * psi [ i - 1 ] * ( 1.0 - 5.0 * h0 * h0 * Ksquare / 12.0 ) / ( 1.0 + ( h0 * h0 * Ksquare / 12 ) ) - psi [ i - 2 ] ) if Endsign * psi [ - 1 ] > psi_right : ElowerLimit = Etrial elif Endsign * psi [ - 1 ] < psi_right : EupperLimit = Etrial else : exit ( ) Etrial = ( EupperLimit + ElowerLimit ) / 2 eigenEnergies [ nQuantum ] = Etrial EupperLimit = Etrial ElowerLimit = Etrial Integral = 0.0 for i in range ( N ) : Integral += 0.5 * h0 * ( psi [ i - 1 ] * psi [ i - 1 ] + psi [ i ] * psi [ i ] ) normCoeff = np . sqrt ( 1.0 / Integral ) psi_final . append ( normCoeff * psi ) potential = np . zeros ( len ( xRange ) ) potential = [ V ( xRange [ i ] ) for i in range ( len ( xRange ) ) ] return xRange , psi_final , eigenEnergies
This method of evaluating eigenvalues is called Numerov method.
This method of evaluating eigenvalues is called Numerov method .
'''
    This method of evaluating eigenvalues is called Numerov method. The method used 
    below can be found in N. Zettili -- Quantum Mechanics.
    ''' # Normalization # psi_final.append(potential)