Mehau Kulyk

Brownian Motion: Langevin Equation in C++

Markus Buchholz


The state of the mechanical system considering the classical approach is specified by a set of positions and momenta. This provides an accurate description of the physical state of multibody systems and the system in a fully deterministic way.

The dynamics of such a multibody system are thus typically described by using a coupled set of differential equations, such as Newton’s equations of motion, individual dynamics of each particle in the system.

However, we can apply the alternative approach to describing dynamics, and describe the dynamics by studying, selected particles moving in the presence of the other particles which we regard as a background, whose detailed dynamics are not treated.

In this case, we select a particle of interest and find an equation that describes the dynamics of a chosen particle in the presence of the other particles. The classical example of this is the Langevin equation developed in a heuristic way by Paul Langevin to describe the Brownian motion.

The theory of Brownian motion is the simplest approximate way to treat the dynamics of nonequilibrium systems, The fundamental equation of motion is the Langevin equation (stochastic differential equation), which can be described as follows,

where, 𝑣 — particle speed, m — particle mass, 𝜆⋅𝑣 — friction force, 𝜂(𝑡) — representing the effect of the collisions with the particles.

It contains both frictional forces (deterministic) and random forces (Gaussian probability distribution). The fluctuation-dissipation theorem relates these forces to each other.


I solved the above differential equation in C++ by applying the Runge–Kutta methods. The source code is on my GitHub.

Below I plotted solutions of particle motion in 2D and 3D. Check how the mass of the particle influences the motion.

Plotting requires incorporating the header file which has to be in the same folder as your cpp (a file you can clone from my repository).
Your program can be compiled as follows.

g++ my_prog.cpp -o my_prog -I/usr/include/python3.8 -lpython3.8//


//folder tree
├── my_prog
├── my_prog.cpp
├── matplotlibcpp.h
particle motion 3D (m = 0.05)
particle motion 3D (m = 1)
particle motion 2D (m = 1)

Thank you for reading.