Seeing Change Geometrically¶
The change equation $X'= f(X)$ says,
“if you are in state $X$, then you are changing at rate $f(X)$.”
Through the function $f$ , the model gives us, for every possible value of the state variable $X$, the change $X'$ at that state value.
For this reason, we will think of $X'$ as giving a change instruction.
For example, recall the bathtub change equation
$$X' = -0.2X$$
where $-0.2$ has the unit of gallon/min
That means, for instance, when the state $X =$ 20 gallon (i.e. the bathtub has $20$ gallon of water) the rate of flow is $-(0.2)(20) = -4$ gallon/min
The negative sign indicates that it is an outflow.
Tangent Space: Geometry Version¶
The set of all possible values of $X$ is the state space of the model,
the set of all possible values of $X'$, that is, all possible change instructions.
For reasons that will become clear soon, we will call this the tangent space of the model.
Suppose our model is of a single animal population $X$. Then geometrically, we think of the state space of $X$ as the positive half (right half) of the real number line $\mathbb{R}_+$.
What’s the tangent space for this model?
It’s the whole of $\mathbb{R}$, positive and negative, because changes can be positive or negative.
Note that state space and tangent space of a given model are two different things. For examples:
The units associate to their elements are different, e.g. gallon (for state space), gallon/hr (for tangent space)
The state space of a herd population is $\mathbb{R}_{+}$ while its tangent space is $\mathbb{R}$ (the herd population can have negative change rate)
Change is movement in state space.
Change instruction at a point is an arrow that points in the direction of the change whose length (size) indicates the magnitude of the change.
And arrows can be described by vectors. We will therefore refer to the change instruction that we get from $X'$ as a change vector.
In one dimension, the vector is pointing in the positive direction (to the right) if the change is positive ($X$ is increasing) and in the negative direction (to the left) if $X$ is decreasing.
The length of the vector will represent the magnitude of the change.
The next step is to think of the change vector as being superimposed on the state value to which it corresponds, as in Figure 1.35.
This is a bit misleading, but a very useful one (especially for visualizing changes) because the change vectors aren’t really in state space.
Rather, they are assigned to points in state space by the change equation.
Vector Field¶
We now have the key idea of this course:
Model = a differential equation, which associate each state $X$ to a change vector $X'$.
That is a function from the state space to the tangent space.
This view of differential equation (change equation) as a function is so important that we give it a special name---vector field
What we have said is that a vector field is a function: State Space $\to$ Tangent Space
Investigate the vector field of the logistic equation
$$ X' = rX(1-X/k)$$
for various parameters $r$ and $k$.
Exercise 1.5.1 If $X'= 0.3X(1 − X/500)$
what change vector is associated with the point $X = 90$? With $X = 600$?
## Define the vector field via a logistic equation
def dX(X):
return 0.3*X*(1-X/500)
## Compute the change vectors at the states
states = [90,600];
vector_field = [(state,dX(state)) for state in states]
"""
In this case the vector_field consisted of two pairs.
The first coordinate of the pair records to state and the second coordinate is the arrow (vector) assigned to that state according to the change equation.
"""
print('The change vector at state X={s1} is {v1:.3f} and the change vector at state X={s2} is {v2:.3f}'.format(s1=vector_field[0][0], v1=vector_field[0][1],\
s2=vector_field[1][0], v2=vector_field[1][1]))
The change vector at state X=90 is 22.140 and the change vector at state X=600 is -36.000
For more information on formatting strings in Python, read:
Exercise 1.5.2 Sketch the vector field for $X'= 0.1X$.
# Import libraries
import numpy as np
import matplotlib.pyplot as plt
# Vector origin location
X = np.linspace(-5,5,10)
Y = [0]
# Directional vectors
U = (0.2)*X
V = [0]
# Creating plot
plt.quiver(X, Y, U, V, color='b', units='xy', scale=1)
plt.title('Vector Field X\' = 0.1X')
# x-lim and y-lim
plt.xlim(-7, 7)
plt.ylim(-0.1,0.1)
# Show plot with grid
plt.grid()
plt.show()
2D Vector Fields¶
In this case there are two state varialbles $(X,Y)$ in our model and the model (vector field) has the form
\begin{align*} X' &= f(X,Y) \\ Y' &= g(X,Y) \end{align*}
for some functions $f,g$ from the state space.
The Spring Model¶
\begin{align*} X' &= V \\ V' &=-X \end{align*}
## Defining the model
def spring_model(state):
X,V = state #this assigns the first coordinate of vec to X and the second coordinate of vec to V
return(array([V,-X-V]))
# A way of plotting the vector field using Python
#Import the libraries
import numpy as np
import matplotlib.pyplot as plt
from numpy import array
#setting the parameters
xmin,vmin,xmax,vmax,nb_points = -2,-2,2,2,15
#making the vector field plots
x = np.linspace(xmin, xmax, nb_points)
v = np.linspace(vmin, vmax, nb_points)
X , V = np.meshgrid(x,v) #create a grid of points for the arrows to attach to.
DX, DV = spring_model(array([X,V])) #applying the change equations
plt.quiver(X, V, DX, DV, color='g') # plotting the vectors
plt.title('Vector field of the Spring Model')
plt.xlabel(r'$X$')
plt.ylabel(r'$V$')
plt.rcParams['figure.figsize']=[8,8]
plt.show()
Exercise 1.5.3 What would the vector field for the Romeo–Juliet model look like?
The Romeo-Juliet system is
\begin{align*} J' &= R\\ R' &= -J \end{align*}
which is just the spring system (up to renaming the variables and twisting the parameters). So the vector for the R-J model look exactly the same as the Spring model.
Exercise 1.5.4 If $X'= Y$ and $Y'= X$, what change vector is associated with the point $(3,5)$?
Exercise 1.5.5 Find the change vector associated with the point $(T,S) = (75,75)$ in the Lotka–Volterra predation model
\begin{align*} T' &= 0.5T − 0.01ST\\ S' &= 0.005ST − 0.2S. \end{align*}
Ans. 1.5.4 $(5,3)$
## Defining the model
def Tuna_Shark_model(state):
T,S = state #this assigns the first coordinate of vec to X and the second coordinate of vec to V
return(array([0.5*T-0.01*S*T,0.005*S*T-0.2*S]))
Tuna_Shark_model((75,75))
array([-18.75 , 13.125])
# A way of plotting the vector field using Python
#Import the libraries
import numpy as np
import matplotlib.pyplot as plt
from numpy import array
#setting the parameters
tmax,smax,nb_points = 100,100,15
#making the vector field plots
t_pos = np.linspace(0, tmax, nb_points)
s_pos = np.linspace(0, smax, nb_points)
T , S = np.meshgrid(t_pos,s_pos) #create a grid of points for the arrows to attach to.
DT, DS = Tuna_Shark_model(array([T,S])) #applying the change equations
plt.quiver(T, S, DT, DS, color='g') # plotting the vectors
plt.title('Vector field of the Tuna-Shark Model',fontsize=15)
plt.xlabel('Tuna', fontsize=15)
plt.ylabel('Shark', fontsize=15)
plt.rcParams['figure.figsize']=[8,8]
plt.show()
Plotting vector fields using SAGE has simplier syntax.
Plotting them in Python using matlibplot give you more control.
Some examples of plot 2D vector fields with Python.
Python Matplotlib examples of vector fields plotting.
We showed how to plot them in Python above. And will show how to plot them in SAGE below
#Declaring the variables
var('X,V')
#The Change Equations
spring_model(X,V) = (V,-X)
vfp = plot_vector_field(spring_model,
(X,-2,2),(V,-2,2), #range of the variables
frame=False,
color="green",
plot_points=15, #the number of sampling points in each variable
axes_labels=("$X$","$V$"),
figsize=5)
vfp.show(aspect_ratio=1)
## Declaring the State Variables
var('S,T')
## The Change Equations
dT = 0.5*T-0.01*S*T
dS = 0.005*S*T-0.2*S
LV_model(S,T) = (dT,dS)
vfp_LV = plot_vector_field(LV_model(S,T),
(T,0,100),(S,0,100), # T first then S, so T-axis is the horizontal axis and the S-axis is the vertical axis.
# This is to match with (T',S')
frame=false,
color="green",
plot_points=10,
axes_labels=(" ","Shark"))
# (100,-10) is just the locate that I put the lable "Tuna"
show(vfp_LV+text("Tuna",(100,-10), color='black', fontsize=18),aspect_ratio=1,figsize=[10,5])