3.1 Interaction Calculation

Course subject(s) 3. Extending the model

The client wants rainbowfish and gouramis in the same aquarium. That might not be a good idea, because the gouramis eat rainbowfish. Will it lead to a stable mix of the two species, or will one of them die out?

On the previous page you have seen the construction of the initial value problem for the rainbowfish population P(t) and the gourami population G(t):

In the next video you will learn how you can use Euler’s Method for a system of differential equations.

Euler's Method for Systems

Subtitles (captions) in other languages than provided can be viewed at YouTube. Select your language in the CC-button of YouTube.

In the video you have learned about Euler’s Method for systems of differential equations.

For the general differential equation

the n-th step of Euler’s method is given by
in which Δt is some time step you have to choose.

Of course, doing calculations by hand quickly becomes laborious. So again we turn to a computer program. The following file contains an example code in Python for a system of differential equations:

Basic_Euler_program_systems.py

First some background information on arrays in Python.

Arrays in Python

For systems of differential equations, it is convenient to combine the different dependent variables in a vector. Here we use

Especially when there are many dependent variables, a vector notation makes the system often clearer and neater, both in analytical calculations and in numerical simulations.

In Python, you could try to implement vectors as lists. However, lists are not appropriate to calculate with. For example, when you try: (3.0,3.0)/2.0, you will get an error message. The numpy package however, does have arrays with which you can implement vectors and matrices: np.array([3.0,3.0])/2 returns array([1.5,1.5]).

Python’s default mode to calculate with vectors and matrices is by element, so beware. For example,   matrix

can be implemented as   A = np.array([[2,3],[4,5]]). When you calculate A*A, or equivalently A**2, Python returns array([[ 4,  9], [16, 25]]), so all four elements have been squared, but this is not the product of the two matrices. To calculate the product of two matrices, you need a special command: np.dot(A,A) which returns the correct array([[ 16,  21], [28, 37]]).