I have the following code:
import numpy as np
from matplotlib import pyplot as plt
from scipy.integrate import odeint
exp = np.exp
pi = np.pi
def func(y, t, W, omega, delta, omega_Rabi):
c_up, c_down = y
dydt = [-1j*np.exp(-1j*delta*t)*(1j*W+omega_Rabi)*c_down,-1j*np.exp(1j*delta*t)*(-1j*W+omega_Rabi)*c_up]
return dydt
W = 2*pi*10
omega_Rabi = 2*pi*300;
delta = 2*pi*5000;
omega = 2*pi*100000;
y0 = [0,1]
t = np.linspace(0, 0.01, 100)
sol = odeint(func, y0, t, args=(W,omega,delta,omega_Rabi))
plt.plot(t, abs(sol[:, 0])**2, 'b')
plt.show()
The code runs and gives me a plot, but it is the wrong one. I am getting this warning:
ComplexWarning: Casting complex values to real discards the imaginary part
output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
so it seems to have something to do with the fact that I am using complex numbers, but I don't know what is it or how to fix it. Can someone help me? Thank you!