I declared the vector Psi_init by just copying the value of Psi. Then, I don't touch the variable Psi_init any more. But when I print the value of Psi_init at the end of the code, the value of Psi_init is changed to the value of Psi after the for-loop. The value is actually changed on the funtion return of the function Runge-Kutta. I don't get why this actually happens.
import numpy as np
from matplotlib import pyplot as plt
from scipy import linalg
#----------------------------------------------------------------
#Function definitions
def f(t,Ham,Psi):
return (-1j*Ham*Psi)
def RungeKutta(t,Ham,Psi,DeltaT):
k1=f(t,Ham,Psi)
k2=f(t+DeltaT/2,Ham,Psi+k1*DeltaT/2)
k3=f(t+DeltaT/2,Ham,Psi+k2*DeltaT/2)
k4=f(t+DeltaT,Ham,Psi+k3*DeltaT)
return Psi+DeltaT/6*(k1+2*k2+2*k3+k4)
#-------------------------------------------------------------------
#Anfangsbedingungen
DeltaT=0.01
finalT=1.0
NumOfIt=int(finalT/DeltaT)+1
omega1=5.0
omega2=3.0
Psi=np.matrix([[1],[0]],dtype=np.complex)
Psi_init=Psi
Ham=np.matrix([[omega1,0],[0,omega2]])
Zustand=np.zeros((2,NumOfIt),dtype=np.complex)
time=np.linspace(0,finalT,NumOfIt,endpoint='true')
#---------------------------------------------------------------------
#Zeitentwicklung
for t in time:
ii=int(t/DeltaT)
Psi[0:2] =RungeKutta(t,Ham,Psi,DeltaT)[0:2]
Zustand[0:2,ii:ii+1]=Psi[0:2]
print Psi_init