232
8 Solving Ordinary Differential Equations
8.3.5 Abstract Problem and Notation
When we had a specific differential equation with one unknown, we quickly turned
to an abstract differential equation written in the generic form u = f (u, t). We refer
to such a problem as a scalar ODE. A specific equation corresponds to a specific
choice of the formula f (u, t) involving u and (optionally) t.
It is advantageous to also write a system of differential equations in the same
abstract notation,
u
= f (u, t),
but this time it is understood that u is a vector of functions and f is also vector. We
say that u = f (u, t) is a vector ODE or system of ODEs in this case. For the SIR
model we introduce the two 3-vectors, one for the unknowns,
u = (S(t), I (t), R(t)),
and one for the right-hand side functions,
f (u, t) = (−βSI, βSI − γ I, γ I) .
The equation u = f (u, t) means setting the two vectors equal, i.e., the components
must be pairwise equal. Since u = (S , I , R ), we get that u = f implies
S
= −βSI,
I
= βSI − γ I,
R
= γ I .
The generalized short notation u = f (u, t) is very handy since we can derive
numerical methods and implement software for this abstract system and in a
particular application just identify the formulas in the f vector, implement these,
and call functionality that solves the differential equation system.
8.3.6 Programming the FE Scheme; the General Case
In Python code, the Forward Euler step
u
n+1
= u
n
+ Δtf (u
n , t n ),
being a scalar or a vector equation, can be coded as
u[n+1] = u[n] + dt*f(u[n], t[n])
both in the scalar and vector case. In the vector case, u[n] is a one-dimensional
numpy array of length m + 1 holding the mathematical quantity u n , and the Python
function f must return a numpy array of length m + 1. Then the expression u[n] +
dt*f(u[n], t[n]) is an array plus a scalar times an array.
8 Solving Ordinary Differential Equations
8.3.5 Abstract Problem and Notation
When we had a specific differential equation with one unknown, we quickly turned
to an abstract differential equation written in the generic form u = f (u, t). We refer
to such a problem as a scalar ODE. A specific equation corresponds to a specific
choice of the formula f (u, t) involving u and (optionally) t.
It is advantageous to also write a system of differential equations in the same
abstract notation,
u
= f (u, t),
but this time it is understood that u is a vector of functions and f is also vector. We
say that u = f (u, t) is a vector ODE or system of ODEs in this case. For the SIR
model we introduce the two 3-vectors, one for the unknowns,
u = (S(t), I (t), R(t)),
and one for the right-hand side functions,
f (u, t) = (−βSI, βSI − γ I, γ I) .
The equation u = f (u, t) means setting the two vectors equal, i.e., the components
must be pairwise equal. Since u = (S , I , R ), we get that u = f implies
S
= −βSI,
I
= βSI − γ I,
R
= γ I .
The generalized short notation u = f (u, t) is very handy since we can derive
numerical methods and implement software for this abstract system and in a
particular application just identify the formulas in the f vector, implement these,
and call functionality that solves the differential equation system.
8.3.6 Programming the FE Scheme; the General Case
In Python code, the Forward Euler step
u
n+1
= u
n
+ Δtf (u
n , t n ),
being a scalar or a vector equation, can be coded as
u[n+1] = u[n] + dt*f(u[n], t[n])
both in the scalar and vector case. In the vector case, u[n] is a one-dimensional
numpy array of length m + 1 holding the mathematical quantity u n , and the Python
function f must return a numpy array of length m + 1. Then the expression u[n] +
dt*f(u[n], t[n]) is an array plus a scalar times an array.
