langevin_dynamics 2¶

Query¶

import numpy as np

def run_langevin_dynamics(x0,v0,gamma,F,n_steps,dt=0.003,T=1.0,m=1):
    """
    This function runs a Langevin dynamics simulation in 1d in an external potential
    It returns the trajectory of x and v.

    The initial position is x0
    The initial velocity is v0
    The temperature is T
    m is the mass
    F(x) is a function that returns the external force
    gamma is the drag coefficient
    """
    x_traj = np.zeros(n_steps)
    v_traj = np.zeros(n_steps)
    [insert]
    return x_traj, v_traj

Output¶

import numpy as np

def run_langevin_dynamics(x0,v0,gamma,F,n_steps,dt=0.003,T=1.0,m=1):
    """
    This function runs a Langevin dynamics simulation in 1d in an external potential
    It returns the trajectory of x and v.

    The initial position is x0
    The initial velocity is v0
    The temperature is T
    m is the mass
    F(x) is a function that returns the external force
    gamma is the drag coefficient
    """
    x_traj = np.zeros(n_steps)
    v_traj = np.zeros(n_steps)
    x_traj[0] = x0
    v_traj[0] = v0
    for i in range(n_steps-1):
        v_traj[i+1] = (v_traj[i] - dt*F(x_traj[i])/m - gamma*v_traj[i]*dt + np.sqrt(2*gamma*T*dt)*np.random.normal())/(1+gamma*dt)
        x_traj[i+1] = x_traj[i] + v_traj[i+1]*dt

    return x_traj, v_traj

Evaluate¶

Go to Google Form