This section gives an example of how the model developed earlier could be extended to account for additional knowledge of the system's structure. Again, if you have not yet been exposed to this particular type of mathematical analysis, simply note that all models can be refined as we gain more knowledge about the system. Think back to the model you identified in the last section. How could you extend this model to make it a better reflection of reality?
Interaction (Euler's method for Systems)
Interaction Calculation
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):
\( \begin{cases}\frac{d P}{d t}=0.7 P(t)-0.007 P^2(t)-0.04 P(t) G(t), & P(0)=20, \\ \frac{d G}{d t}=-0.25 G(t)+0.008 P(t) G(t), & G(0)=5 .\end{cases} \)
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
In the video you have learned about Euler's Method for systems of differential equations.
For the general differential equation
\( \dfrac{d \vec X}{dt} = \vec F(t, \vec X) \),
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
\(\vec{X}(t)=\left[\begin{array}{l}
P(t) \\
G(t)
\end{array}\right] .\)
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
\( A=\left[\begin{array}{l}2 & 3 \\4 & 5\end{array}\right] \)
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]]).