I am really new to python and numpy as it is the first real programming language I use. Before I started using it I only worked with Mathematica to do my assignments, but since we have to do numerical computations now Mathematica isn't really the right thing to use anymore. I really liked numpy so far because it feels much lighter and far more instinctive than Mathematica. But now I came to a point where I really couldn't go any further with some trying plus information from the internet.
So, my problem is about the Crank-Nicolson method applied to Schrödingers Equation. Leaving out all my definitions of constants and my Matrices, I started with an initial function:
u = np.asarray([
(0 if xx==-L or xx==L else (1/(np.sqrt(np.sqrt(np.pi)*l))))*(np.e**
(1j*k*(xx-y)-(((xx+y)**2)/(2*l**2)))) for xx in x])
which is discretized within a grid x. Furthermore:
q = np.zeros((N-1),dtype=complex)
for i in range(N-1):
if i==0:
q[i] = M[i,i+1]/M[i,i]
elif i==N-2:
q[i] = 0
else:
q[i] = M[i,i+1]/(M[i,i]-M[i,i-1]*q[i-1])
and also:
def dot(x):
dot = Mkj.dot(x)
return dot
qq = np.zeros((N-1),dtype=complex)
for i in range(N-1):
if i==0:
qq[i] = dot(u)[i]
else:
qq[i] = ((dot(u)[i]-M[i,i-1]*qq[i-1])/(M[i,i]-M[i,i-1]*q[i-1]))
and at last:
v = np.zeros((N-1),dtype=complex)
for i in range(N-1):
if i==N-2:
v[i] = qq[i]
else:
v[i] = qq[i]-q[i]*v[i+1]
This is now my initial function after one time expansion.
My problem is that i have no idea how i repeat this calculation over various step with looping the outcoming function, because i have no idea how to define a function over looped arrays.
Thanks in advance, Dear Greetings,
Streichholzritter