You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/steady_state_functionality/examples/nullcline_plotting.md
+21-56Lines changed: 21 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# [Plotting Nullclines and Steady States in Phase Space](@id nullcline_plotting)
2
-
In this tutorial we will show how to extract a system's steady states and [nullclines](https://en.wikipedia.org/wiki/Nullcline), and how to plot these in [phase space](https://en.wikipedia.org/wiki/Phase_space). Generally, while nullclines are not directly needed for much analysis, plotting these can give some understanding of a system's steady state and stability properties. While nullclines can be "brute forced" (by solving their equations across grids of values), we will here use [BifurcationKit.jl](https://github.com/bifurcationkit/BifurcationKit.jl) to track their path exactly.
2
+
In this tutorial we will show how to extract a system's steady states and [nullclines](https://en.wikipedia.org/wiki/Nullcline), and how to plot these in [phase space](https://en.wikipedia.org/wiki/Phase_space). Generally, while nullclines are not directly needed for much analysis, plotting these can give some understanding of a system's steady state and stability properties.
3
3
4
4
For an ordinary differential equation
5
5
```math
@@ -13,20 +13,14 @@ For an ordinary differential equation
13
13
the $i$'th nullcline is the surface along which $\frac{dx_i}{dt} = 0$, i.e. the implicit surface given by $f_i(x_1,\dots,x_n) = 0$. Nullclines are frequently used when visualizing the phase-planes of two-dimensional models (as these can be easily plotted).
14
14
15
15
## [Computing nullclines and steady states for a bistable switch](@id nullcline_plotting_computation)
16
-
For our example we will use a simple bistable switch model, consisting of two species ($X$ and $Y$) which mutually inhibit each other through repressive Hill functions. We will create our model [programmatically](@ref programmatic_CRN_construction).
16
+
For our example we will use a simple bistable switch model, consisting of two species ($X$ and $Y$) which mutually inhibit each other through repressive Hill functions.
17
17
```@example nullcline_plotting
18
18
using Catalyst
19
-
t = default_t()
20
-
@parameters v K n
21
-
@species X(t) Y(t)
22
-
rxs = [
23
-
Reaction(hillr(Y, v, K, n), [], [X]),
24
-
Reaction(hillr(X, v, K, n), [], [Y]),
25
-
Reaction(1.0, [X], []),
26
-
Reaction(1.0, [Y], []),
27
-
]
28
-
@named bs_switch = ReactionSystem(rxs, t)
29
-
bs_switch = complete(bs_switch)
19
+
bs_switch = @reaction_network begin
20
+
hillr(Y, v, K, n), 0 --> X
21
+
hillr(X, v, K, n), 0 --> Y
22
+
1.0, (X,Y) --> 0
23
+
end
30
24
```
31
25
32
26
Next, we compute the steady states [using homotopy continuation](@ref homotopy_continuation).
@@ -36,45 +30,23 @@ ps = [v => 1.0, K => 0.6, n => 4.0]
Finally, we will compute the nullclines. We will first extract our model's steady state equations (which we do by creating a `NonlinearSystem`).
40
-
```@example nullcline_plotting
41
-
nlsys = convert(NonlinearSystem, bs_switch)
42
-
eqs = equations(nlsys)
43
-
```
44
-
Here, each equation is an expression of the two variables ($X$ and $Y$). We wish to plot $Y$ as a function of $X$. To do this, we will substitute the species variable $X$ with the parameter $Xpar$. This will enable us to carry out bifurcation analysis of the equations' solutions as $Xpar$ is varied
To input these into BifurcationKit we need to convert these into `NonlinearSystem`s.
33
+
Finally, we will compute the nullclines. First we create a function which, for species values $(X,Y)$, returns the evaluation of the model's ODE's right-hand side.
51
34
```@example nullcline_plotting
52
-
@named nc_X_sys = NonlinearSystem([nc_eq_X])
53
-
@named nc_Y_sys = NonlinearSystem([nc_eq_Y])
54
-
nc_X_sys = complete(nc_X_sys)
55
-
nc_Y_sys = complete(nc_Y_sys)
56
-
nothing # hide
57
-
```
58
-
Finally, for our nullcline equations, we can use BifurcationKit's `continuation` function to track their solutions across all values of $Xpar$ (the workflow is similar to when we used `bifurcationdiagram`[here](@ref bifurcation_diagrams)).
We are now ready to create our plot. We will plot the steady states using `scatter`. We use the `steady_state_stability` function to [compute steady state stabilities](@ref steady_state_stability) (and use this to determine how to plot the steady state markers). For the nullclines, we plot their `.x` values (the variable we solve for, $Y$) against their `.param` values (the parameter which value we vary, $Xpar$).
41
+
Next, we plot our nullclines by using Plot.jl's [`contour` function](https://docs.juliaplots.org/latest/series_types/contour/). Here, we plot the $0$ contour lines (which corresponds to the nullclines) for both the $X$ and $Y$ nullclines. We will plot the steady states using `scatter`. We use the `steady_state_stability` function to [compute steady state stabilities](@ref steady_state_stability) (and use this to determine how to plot the steady state markers).
Here we can see how the steady states occur at the nullclines intersections.
95
67
96
-
!!! warn
97
-
BifurcationKit's `continuation` function will not detect disjoint branches, and here we can only use it because we know that each nullcline consists of a single branch. To handle nullclines with disjoint branches, consider using [deflated continuation](@ref bifurcation_diagrams_disjoint_branches) (or possibly a package like [Contour.jl](https://github.com/JuliaGeometry/Contour.jl)).
68
+
!!! note
69
+
Here we use an inherent Plots function to plot the nullclines. However, there are also specialised packages for these kinds of plots, such as [ImplicitPlots.jl](https://github.com/saschatimme/ImplicitPlots.jl).
98
70
99
71
## [Plotting system directions in phase space](@id nullcline_plotting_directions)
100
72
One useful property of nullclines is that the sign of $dX/dt$ will only switch whenever the solution crosses the $dX/dt=0$ nullcline. This means that, within each region defined by the nullclines, the direction of the solution remains constant. Below we use this to, for each such region, plot arrows showing the solution's direction.
101
73
```@example nullcline_plotting
102
-
# Create a function which evaluates the ODE at a point in phase space.
103
-
nlprob = NonlinearProblem(complete(nlsys), [X => 0.0, Y => 0.0], ps)
0 commit comments