# Solving Schrodinger Eq. w/ Crank Nicolson Method

• WiFO215
In summary, the Schrodinger equation is a fundamental equation in quantum mechanics that describes the time evolution of a quantum system. The Crank Nicolson method is a numerical method for solving partial differential equations, such as the Schrodinger equation, which is more accurate and stable compared to other methods. It is also advantageous for its quick convergence and ability to handle larger time steps. However, it may be computationally expensive and difficult to implement for certain types of problems with complicated boundary conditions.
WiFO215
I have tried discretizing the Schrodinger equation using the crank nicolson method and then have tried to solve the resulting tri-diagonal matrix using the algorithm on Wikipedia.

http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm

However, I am not getting the required result and cannot put my finger on it. Please help! I have attached the code below.

h is my space step and deltat is my time step. J = total number of space steps and K = total number of time steps

Code:
import numpy as np

#----------------------------------------------------#

#GIVEN DATA

h = 0.01
deltat = 0.001

J = 500
K = 500

phi_a = np.zeros(shape=(K,J), dtype = np.complex)

#BOUNDARY CONDITIONS#

for p in range(1,J-1):
phi_a[0][p] = np.sin(np.pi*(p+1)/J)

#----------------------------------------------------#

a = np.ones(J, dtype=np.complex)/(4*h**2)
a[0], a[J-1] = 0,0

c = np.ones(J, dtype=np.complex)/(4*h**2)
c[0], c[J-1] = 0,0

#----------------------------------------------------#

def b(k):
b = np.ones(J, dtype=np.complex)
for p in range(1,J-1):
b[p] = (1j/(deltat)) - (1/(2*h**2))

return(b)

def d(k):
d = np.ones(J, dtype=np.complex)

for p in range(1,J-2):
d[p] = -(phi_a[k][p+1]/(4*h**2)) + (phi_a[k][p]*((1j/deltat) + 1/(2*h**2))) - (phi_a[k][p-1]/(4*h**2))

d[0] = phi_a[k+1][0]
d[J-1] = phi_a[k+1][J-1]

return(d)

#----------------------------------------------------#

def tdms(a,c,k,s,b,d):
b,d = b(k),d(k)

for p in range(1,J-1):
c[p] = c[p]/(b[p] - c[p-1]*a[p])

for p in range(J):
d[p] = (d[p]-d[p-1]*a[p])/(b[p] - c[p-1]*a[p])

for p in range(J-2,0,-1):
s[k+1][p] = d[p] - c[p]*s[k+1][p+1]

return

#----------------------------------------------------#

for k in range(0,K-1):
tdms(a,c,k,phi_a,b,d)

#----------------------------------------------------#

anphi_a = open('test.txt','w')
for W in range(K):
for Q in range(J-1):
anphi_a.write(str(phi_a[W][Q]) + ', ')
anphi_a.write(str(phi_a[W][J-1]) + '\n')
anphi_a.close()

This is written in Python, which is nearly pseudo-code, so most of you should be able to understand it. Please help!

Hi there,

It's difficult to pinpoint the exact issue without more information, but here are a few suggestions that may help:

1. Double check your boundary conditions: Make sure they are correctly implemented and are consistent with the initial conditions.

2. Check your indexing: Make sure that you are using the correct indices when accessing and assigning values to arrays. A simple mistake in indexing can lead to unexpected results.

3. Consider using a different algorithm: The tridiagonal matrix algorithm is known to have stability issues for certain types of matrices. You may want to try using a different algorithm, such as the LU decomposition method, to solve the resulting matrix.

4. Check for convergence: Make sure that your solution is converging to a steady state. If it is not, then there may be a problem with your discretization or algorithm.

5. Debug your code: Use print statements or a debugger to track the values of your variables and make sure they are behaving as expected.

I hope these suggestions help. Good luck with your research!

## 1. What is the Schrodinger equation?

The Schrodinger equation is a fundamental equation in quantum mechanics that describes the time evolution of a quantum system. It is used to calculate the probability of finding a particle at a particular position in space and time.

## 2. What is the Crank Nicolson method?

The Crank Nicolson method is a numerical method for solving partial differential equations, such as the Schrodinger equation. It is a combination of the forward and backward Euler methods, which results in a more accurate and stable solution.

## 3. Why is the Crank Nicolson method used to solve the Schrodinger equation?

The Crank Nicolson method is used to solve the Schrodinger equation because it is more accurate and stable compared to other numerical methods. It also converges quickly to the exact solution, making it a popular choice for solving the Schrodinger equation.

## 4. What are the advantages of using the Crank Nicolson method?

The Crank Nicolson method has several advantages, including its accuracy, stability, and quick convergence to the exact solution. It also allows for a larger time step, making it more efficient for solving time-dependent problems.

## 5. Are there any limitations to using the Crank Nicolson method for solving the Schrodinger equation?

While the Crank Nicolson method is a popular and useful method for solving the Schrodinger equation, it does have some limitations. It can be computationally expensive and may not be suitable for all types of problems. Additionally, it can be challenging to implement for systems with complicated boundary conditions.

• Programming and Computer Science
Replies
1
Views
2K
• Programming and Computer Science
Replies
3
Views
1K
• Programming and Computer Science
Replies
2
Views
1K
• Programming and Computer Science
Replies
55
Views
4K
• Programming and Computer Science
Replies
6
Views
1K
• Programming and Computer Science
Replies
2
Views
2K
• Programming and Computer Science
Replies
5
Views
1K
• Programming and Computer Science
Replies
97
Views
7K
• Programming and Computer Science
Replies
15
Views
2K
• Programming and Computer Science
Replies
9
Views
2K