-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07-ODE_multidimension.Rmd
271 lines (179 loc) · 4.81 KB
/
07-ODE_multidimension.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# ODE in multi-dimensions
## Terminology
$$\dot{X} = f(X, t, \Theta)$$
where:
- `X` is a vector of state variables (*e.g.* population size of several species)
- `t` stands for time
- `Θ` includes all the parameters
- `f` is a multi-dimensional function
## Linear system
Function `f` and its parameters `\theta`.
<!-- degeneracy -->
### General case
$$
\left\{
\begin{array}{l}
\dot{x}_1 = \sum_i a_{1,i}x_i\\
... \\
\dot{x}_n = \sum_i a_{n,i}x_{i} \\
X(0) = X_0
\end{array}
\right.
$$
Using matrices:
$$\dot{X} = AX$$
Linear system in $n$ dimensions.
### Trivial case
If $i \neq j \Rightarrow 0$ then A in diagonal:
$$
\left\{
\begin{array}{l}
\dot{x}_1 = a_{1,1}x_1\\
... \\
\dot{x}_n = a_{1,1}x_{n} \\
X(0) = X_0
\end{array}
\right.
$$
Then, all state variables are independent and the answer is obtained by solving
$n$ times a one-dimensional problem (described in the previous chapter).
### Diagonalizations
Now let's go back to the general case and assume that A is a diagonalizable
matrix (see Diagonalization on [wikipedia](https://en.wikipedia.org/wiki/Diagonalizable_matrix#Diagonalization)),
*i.e.* that it exits: $P$ and $D$ such as:
$$A = PDP^{-1}$$
This operation is a [change of basis](https://en.wikipedia.org/wiki/Change_of_basis),
we actually assume that it exists a basis in which our problem is as simple as the trivial
case, $P$ is the matrix that does the conversion. If our
### Graphical examples
```{r loadlinear, echo = F}
<<linear>>
```
```{r linear1, fig.width = 9, fig.height = 8}
beta <- list(
matrix(c(-1, 0, 0, -1), 2),
matrix(c(1, 0, 0, -1), 2),
matrix(c(-1, 0, 0, 1), 2),
matrix(c(1, 0, 0, 1), 2)
)
par(mfrow = c(2,2))
for (i in 1:4) intLinear(beta = beta[[i]])
```
```{r linear2, fig.width = 9, fig.height = 8}
beta <- list(
matrix(c(0, -1, -1, 1), 2),
matrix(c(0, 1, -1, 0), 2),
matrix(c(0, -1, 1, 0), 2),
matrix(c(0, 1, 1, 0), 2)
)
par(mfrow = c(2,2))
for (i in 1:4) intLinear(beta = beta[[i]])
```
```{r linear3, fig.width = 9, fig.height = 8}
beta <- list(
matrix(c(0, 1, -1, -1), 2),
matrix(c(0, 1, -1, 1), 2),
matrix(c(1, 1, -1, 1), 2),
matrix(c(-1, 1, -1, 1), 2)
)
par(mfrow = c(2,2))
for (i in 1:4) intLinear(beta = beta[[i]])
```
```{r linear4, fig.width = 9, fig.height = 8}
beta <- list(
matrix(c(0, 1, -1, -2), 2),
matrix(c(0, 1, -1, -1), 2),
matrix(c(0, 1, -1, -.5), 2),
matrix(c(0, 1, -1, -.1), 2)
)
par(mfrow = c(2,2))
for (i in 1:4) intLinear(beta = beta[[i]], mxt =100)
```
```{r linear5, fig.width = 9, fig.height = 8}
beta <- list(
matrix(c(0, 2, -1, -.1), 2),
matrix(c(0, 1, -1, -.1), 2),
matrix(c(0, .5, -1, -.1), 2),
matrix(c(0, .1, -1, -.1), 2)
)
par(mfrow = c(2,2))
for (i in 1:4) intLinear(beta = beta[[i]], mxt =100)
```
## Non-Linear systems
### Finding the eigen values
$$AX = \lambda X$$
Solutions of:
$$\left(A - \lambda I_n\right) X = 0_n$$
## Examples
> Symetry drives weird shit! (K. S. McCann)
### Lotka Volterra
#### Intro
Classical model see @volterra_fluctuations_1927.
Equations:
$$
\left\{
\begin{array}{l}
\dot{R} = rR - aCR \\
\dot{C} = eaCR - mC
\end{array}
\right.
$$
#### First find equilibria and isolclines
$$
\left\{
\begin{array}{l}
\dot{R} = 0 \Leftrightarrow C = r/a; C*=r/a \\
\dot{C} = 0 \Leftrightarrow R = m/(ea); R* = m/(ea)
\end{array}
\right.
$$
#### Jacobian matrix
\begin{pmatrix}
r-aC* & -aR* \\
eaC* & eaR*-m
\end{pmatrix}
at the non-trivial equilibrium:
\begin{pmatrix}
0 & -aR* \\
eaC* & 0
\end{pmatrix}
#### Diagonalisation
\begin{pmatrix}
-\lambda & -aR* \\
eaC* & -\lambda
\end{pmatrix}
To get the two eigen values we must solve:
$$\lambda^2 + mr = 0$$
$$eig = \pm i \sqrt{mr}$$
(pure imaginary, so => spins)
#### Lotka-Volterra with`odeintr`
[`odeint`](http://headmyshoulder.github.io/odeint-v2/) is a C++ library, Timothy H. Keitt (may ring the bell to some of you)
has created a R package that wrapps around this library: [odeintr](https://github.com/thk686/odeintr).
Example from the GitHub project page:
```{r}
library(odeintr)
dxdt = function(x, t) c(x[1] - x[1] * x[2], x[1] * x[2] - x[2])
obs = function(x, t) c(Prey = x[1], Predator = x[2], Ratio = x[1] / x[2])
system.time({x = integrate_sys(dxdt, rep(2, 2), 20, 0.01, observer = obs)})
plot(x[, c(2, 3)], type = "l", lwd = 2, col = "steelblue", main = "Lotka-Volterra Phase Plot")
```
### Rozenzweig-McArthur model
#### Into
Another clasical, see @rosenzweig_graphical_1963 and @rosenzweig_paradox_1971
and McCann's book!
$$
\left\{
\begin{array}{l}
\dot{R} = rR(1-\frac{R}{K}) - \frac{aCR}{R+R0} \\
\dot{C} = \frac{eaCR}{R+R0} - mC
\end{array}
\right.
$$
<!-- 2Bedone
transcritical happens when one equilibrimu always there
Stable => unstabe
recepies for transcritical!
TC => unstable stable
Hopf Bofirctution => imaginary / cycle for ever
hop to K
Do the bifurcation diagramm K against Cmin Cmax -->