velocity_verlet_integration 2¶

Query¶

import numpy as np

def verlet_integrate(x0, v0, F, steps=1000, dt=0.001):
    """
    Integrates given force field with Velocity-Verlet integration
    """
    x_traj = np.zeros(steps)
    v_traj = np.zeros(steps)
    [insert]
    return x_traj, v_traj

Output¶

import numpy as np

def verlet_integrate(x0, v0, F, steps=1000, dt=0.001):
    """
    Integrates given force field with Velocity-Verlet integration
    """
    x_traj = np.zeros(steps)
    v_traj = np.zeros(steps)
    x_traj[0] = x0
    v_traj[0] = v0
    for i in range(steps-1):
        x_traj[i+1] = x_traj[i] + v_traj[i]*dt + 0.5*F(x_traj[i])*dt**2
        v_traj[i+1] = v_traj[i] + 0.5*(F(x_traj[i]) + F(x_traj[i+1]))*dt

    return x_traj, v_traj

Evaluate¶

Go to Google Form