ornstein_uhlenbeck, a MATLAB code which approximates solutions of the Ornstein-Uhlenbeck stochastic differential equation (SDE) using the Euler method and the Euler-Maruyama method.

The Ornstein-Uhlenbeck stochastic differential equation has the form:

        dx(t) = theta * ( mu - x(t) ) dt + sigma dW,   
        x(0) = x0.
where and the equation is to be integrated over the interval [0,tmax].

The starting value x0 represents a deviation from the mean value mu. The decay rate theta determines how fast x(t) will move back towards its mean value. The coefficient sigma determines the relative magnitude of stochastic perturbations.

In general, the solution starts at x0 and over time moves towards the value mu, but experiences random "wobbles" whose size is determined by sigma. Increasing theta makes the solution move towards the mean faster.


The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.


ornstein_uhlenbeck is available in a C version and a C++ version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

black_scholes, a MATLAB code which implements some simple approaches to the Black-Scholes option valuation theory, by Desmond Higham.

brownian_motion_simulation, a MATLAB code which simulates Brownian motion in an M-dimensional region.

cnoise, a MATLAB code which generates samples of noise obeying a 1/f^alpha power law, by Miroslav Stoyanov.

colored_noise, a MATLAB code which generates samples of noise obeying a 1/f^alpha power law.

correlation, a MATLAB code which contains examples of statistical correlation functions.


pce_ode_hermite, a MATLAB code which sets up a simple scalar ODE for exponential decay with an uncertain decay rate, using a polynomial chaos expansion in terms of Hermite polynomials.

pink_noise, a MATLAB code which computes a "pink noise" signal obeying a 1/f power law.

sde, a MATLAB code which illustrates the properties of stochastic differential equations (SDE's), and common algorithms for their analysis, including the Euler method, the Euler-Maruyama method, and the Milstein method, by Desmond Higham;

stochastic_diffusion, a MATLAB code which implements several versions of a stochastic diffusivity coefficient.

stochastic_rk, a MATLAB code which applies a Runge Kutta (RK) scheme to a stochastic differential equation.


  1. Desmond Higham,
    An Algorithmic Introduction to Numerical Simulation of Stochastic Differential Equations,
    SIAM Review,
    Volume 43, Number 3, September 2001, pages 525-546.

Source Code:

Last revised on 22 February 2019.