Ordinary differential equations (ODEs)

Ordinary differential equations (ODEs) can be implemented in the EQUATION: block of the [LONGITUDINAL] section. The ODEs describe a dynamical system and are defined by a set of equations for the derivative of each variable, the initial conditions, the starting time and the parameters.

The keyword ddt_ in front of a variable name, as ddt_x and ddt_y, defines the derivative of the ODE system. The variable names denote the components of the solution. These variables are defined at the whole [LONGITUDINAL] section level through their derivatives. The derivatives themselves aren’t variables but keywords, and cannot be referenced by other equations nor be defined under a conditional statement.

Initial conditions
The keyword t0 defines the initial time t_0 of the differential equation, while the variable names with suffix _0 define the  initial conditions of the system. More precisely, in a differential equation for the variable x, x is defined at t\leq t_0 by the initial condition x_0, i.e. x(t)=x_0 and by the differential equation after t_0.

Linking administration with ODEs
Mlxtran provides the PK macro depot() that can be used to link the administration from a data set with the model. Details and examples how to use depot() for the administration are given here.

We consider in this example a first order differential equation on x defined by:

\left\{\begin{array}{l} \dot{x} = -kx \\ x(t)=V,~~\textrm{for}~~t\leq10\end{array}\right.

where (V,k)=(10,.05), this ODE is typically a linear elimination process of a volume. This model is implemented in the file mlxt_ode.txt:

DESCRIPTION: Model description with a simple ODE representing a linear elimination precess of a volume
input = {V, k}

t0 = 10
x_0 = V
ddt_x = -k*x

Here, the Mlxtran model define above is used with Mlxplore with the parameters (V,k)=(10,.05). The simulation result is shown in the figure below. One can see the evolution of x w.r.t. time, one can clearly see the impact of the initialization and its timing.

Rules and Best Practices 

  • We encourage the users to define the initial conditions explicitly, although the default initial value is x_0=0.
  • When no starting time t0 is defined in the Mlxtran model for Monolix then by default t0 is selected to be equal to the first dose or the first observation, whatever comes first.
  • If t0 is defined and no differential equation is used, an error will raise.
  • Initial conditions can depend on time
  • Initial conditions can depend on an input parameter. Therefore, initial condition values can also be estimated in Monolix.
  • Only first order differential equation can be used with Mlxtran. If you want to use a differential equation of the form \frac{d^{n}x}{dt^n}=f(x,\phi), you need to transform the higher order differential equation into a first order differential equations by defining n successive differential equations as proposed in the following “Best Practices Ex. 1: Second order differential equation”.
  • The derivatives of a ODE system cannot be conditional, i.e. ddt_ cannot be used within an if statement. Instead, conditional intermediate variables for the values of the derivatives should be used as shown in “Best Practices Ex. 2: IF statement”. A conditional statement can be built by combining the keywords if, elseif,  else and end. Several elseif keywords can be chained, and the conditions are exclusive in sequence. A default value can be provided using the keyword else, but also as a simple definition preceding the conditional structure. An unspecified conditional value is null. The enclosed variables are not local variables, which means that a variable with remaining conditional definitions is still incomplete and cannot be referenced into another definition, even under the same condition.

Best Practices Ex. 1: Second order differential equation
If you want to use a second order differential equation of the type \ddot{x} +\dot{x}+x = 0, with (x(0),\dot{x}(0))=(a,b), the structural model in Mlxtran writes

input = {a, b}

t0 = 0
x_0 = a
dx_0 = b
ddt_x = dx
ddt_dx = -x-dx

Best Practices Ex. 2: IF statement
If a parameter value depends on a condition, it can be written with in Mlxtran with the usual if-else-end syntax. For example, if a parameter c should be 1 if t\leq 10 and 2 otherwise, write

if t<=10
   c = 1
   c = 2

Derivatives cannot be written within an if-else-end structure. Instead, intermediate variables should be used. For example, if a derivative \frac{dx}{dt} should be 1 if t\leq 10 and 2 otherwise, write

if t<=10
   dx = 1
   dx = 2
ddt_x = dx