Integrating ordinary differential equations
The following examples demonstrate how to integrate various
differential equations using
kontrast.integrateODE()
. Please refer to the
documentation on
integrating differential equations
for details on all individual input and output properties.
Simple sets of equations
The following interactive code examples show first how to use the derivative callback function and secondly how to enter the system of equations using the Kontrast math syntax.
Decay
Differential equation:
Trigonometric functions
The following set of differential equations describes the sine and cosine functions:
Harmonic oscillator
The following set of differential equations is equivalent to the equation of motion of the harmonic oscillator (m\ddot q=-kq-\gamma \dot q):
Incorporating conditional logic
Decay with switching the decay constant
In the following example we include a jump in the decay constant
Approaches like this are best implemented using the derivative
callback function (as it provides the most flexibility). However, in
this particular example we can also use the math parser with the
condition
function.