Python - Differential Equation - ODE 005 UiA Logo

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


We have two coupled ordinary differential equations including a step function:

2*dx/dt = -x(t) + u(t)

5*dy/dt = -y(t) + x(t)

with initial values x(0) = 0 and y(0) = 0.
The function u is given by:

u = u(t) = 2*S(t-5)

where S(t-a) is a step function that changes from zero to one at t = a.


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 four parameters:
model : function call where you have the mathematical model in the diff.eq.
z0    : initial value
tspan : time array
args  : step function
The two first parameters (model and z0) are transferred to the first parameter z in the model function.
The body part (line 15-20) of model contains the mathematical model of the diff.eq.


Notice how the function model solves two differential equations at once, returning an array with both solutions.

ODE 005 - Graph



MatRIC Logo