def test_Ehrenfest2(sys): """ Test the second Ehenfest theorem for the specified quantum system """ times = sys.dt * np.arange(len(sys.P_average)) dP_dt = np.gradient(sys.P_average, sys.dt) print("%.2e" % np.linalg.norm(dP_dt - sys.P_average_RHS)) plt.plot(times, dP_dt, '-r', label='$d\\langle\\hat{p}\\rangle / dt$') plt.plot(times, sys.P_average_RHS, '--b', label='$\\langle -U\'(\\hat{x})\\rangle$') plt.legend() plt.ylabel('force') plt.xlabel('time $t$ (a.u.)')
def test_Ehrenfest1(sys): """ Test the first Ehenfest theorem for the specified quantum system """ times = sys.dt * np.arange(len(sys.x_average)) dx_dt = np.gradient(sys.x_average, sys.dt) print("{:.2e}".format(np.linalg.norm(dx_dt - sys.x_average_rhs))) plt.plot(times, dx_dt, '-r', label='$d\\langle\\hat{x}\\rangle / dt$') plt.plot(times, sys.x_average_rhs, '--b', label='$\\langle\\hat{p}\\rangle$') plt.legend() plt.ylabel('momentum') plt.xlabel('time $t$ (a.u.)')