Python - Differential Equation - ODE 002 UiA Logo

[Main Menu][Prev][Next]
ODE 002 - Code


We have the ordinary differential equation:

dy/dt = - k*y

where y = y(t), k = - 0.1, -0.2, -0.3 and initial value y(0) = 0


This is the same as the previous example, except that we now want to solve three different differential equations (one for each of the three values of the constant k). We can do this passing an extra arguments to the model function.


To the left you see the code for a Python program solving this differential equation numerically and drawing the graph.

The function odeint from the library scipy.integrate solve this differential equation.
odeint has three parameters:
model : function call where you have the mathematical model in the diff.eq.
y0    : initial value
t     : time array
The two first parameters (model and y0) are transferred to the first parameter y in the model function.
The body part (line 15-17) of model contains the mathematical model of the diff.eq.

ODE 002 - Graph



MatRIC Logo