# real plot plt.figure(2) plt.clf() plt.title('Real Space Trajectory') plt.plot(q[:, 0], q[:, 1]) plt.xlabel('Position, $x$') plt.ylabel('Position, $y$') plt.show() # calculation with the Stoemer-Verlet method q = np.zeros((N + 1, 2)) p = np.zeros((N + 1, 2)) q[0, 0] = 1.0 p[0, 1] = 1.0 for ii in range(0, N): q[ii + 1], p[ii + 1] = step.stoemerstep(V, q[ii], p[ii], Dt) # phase plot plt.figure(3) plt.clf() plt.subplots_adjust(wspace = 0.3) plt.subplot(121) plt.title('Phase Plot in $x$') plt.plot(q[:, 0], p[:, 0]) plt.xlabel('Position, $x$') plt.ylabel('Momentum, $p_x$') plt.subplot(122) plt.title('Phase Plot in $y$') plt.plot(q[:, 1], p[:, 1]) plt.xlabel('Position, $y$') plt.ylabel('Momentum, $p_y$')
b = np.zeros(N + 1, dtype = np.float64) e2norm = np.zeros(N + 1, dtype = np.float64) energyError = np.zeros(N + 1, dtype = np.float64) phi = np.zeros(N + 1, dtype = np.float64) dphidq_analytic = np.zeros(N + 1, dtype = np.float64) dphidq_numeric = np.zeros(N + 1, dtype = np.float64) # initial conditions q[0] = 1.9 v[0] = -0.0001 energyConst = 0.5*v[0] + LJ(q[0]) # calcualte phase space for ii in range(0, N): t[ii + 1] = t[ii] + Dt q[ii + 1], v[ii + 1] = step.stoemerstep(LJ, q[ii], v[ii], Dt, 35.0) dphidq = -deriv.derivative(LJ, q[ii], np.abs(q[ii + 1] - q[ii]), False)[0] d2phidq2 = -deriv.derivative(LJdiff, q[ii], np.abs(q[ii + 1] - q[ii]), False)[0] a[ii] = np.max([1, d2phidq2]) E = 0.5*v[ii]**2 + LJ(q[ii]) b[ii] = 0.5*np.sqrt(dphidq**2 + 2*d2phidq2**2*(E - LJ(q[ii]))) energyError[ii] = E - energyConst # plot plt.figure(1) plt.clf() ax1 = plt.subplot2grid((3, 2), (0, 0), rowspan = 3) ax1.plot(q, v) plt.title('Phase Plot') plt.xlabel('Generalised Coordainte, $q$') plt.ylabel('Generalised Velocity, $v(q)$')