Skip to content

Commit

Permalink
fix eqs
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoming committed Feb 2, 2024
1 parent 43f536a commit 20e9076
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Binary file added docs/assets/predator_prey_fig.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ makedocs(;
edit_link="main",
assets=String[],
),
pages=["Home" => "index.md", "Tutorial" =>"tutorial.md", "API" => "api.md"],
pages=["Home" => "index.md", "Tutorial" =>"predator_prey_tutorial.md", "API" => "api.md"],
warnonly=true,
)

Expand Down
13 changes: 9 additions & 4 deletions docs/src/tutorial.md → docs/src/predator_prey_tutorial.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
```@meta
EditURL = "../../examples/predator_prey_fig.jl"
EditURL = "../../examples/predator_prey_tutorial.jl"
```

# Tutorial: Using LinearNoiseApproximation.jl to solve a Lotka-Volterra model

This example demonstrates how to use `LinearNoiseApproximation.jl` package to solve a Lotka-Volterra model using the Linear Noise Approximation (LNA) and compare it to the stochastic
trajectories obtained using the Gillespie algorithm.

````@example predator_prey_fig
````@example predator_prey_tutorial
using LinearNoiseApproximation
using DifferentialEquations
using Catalyst
Expand All @@ -18,14 +18,16 @@ using Plots
## Define the Lotka-Volterra model
The Lotka-Volterra model describes the dynamics of predator-prey interactions in an ecosystem. It assumes that the prey population $U$ grows at a rate represented by the parameter $\alpha$ in the absence of predators, but decreases as they are consumed by the predator population $V$ at a rate determined by the interaction strength parameter, $\beta$. The predator population decreases in size if they cannot find enough prey to consume, which is represented by the mortality rate parameter, $\delta$.
The corresponding ODE system reads
```math
\begin{equation}
\begin{aligned}
\frac{\mathrm{d}U}{\mathrm{d} t} & = \alpha U - \beta U V,\\
\frac{\mathrm{d}V}{\mathrm{d} t} & = \beta U V - \delta V,
\end{aligned}\quad t\in (0, t_{\text{end}}).
\end{equation}
```

````@example predator_prey_fig
````@example predator_prey_tutorial
rn = @reaction_network begin
@parameters α β δ
@species U(t) V(t)
Expand All @@ -38,7 +40,7 @@ end
## Convert the model to a JumpSystem for the Gillespie algorithm
Using `Catalyst.jl` we can convert `ReactionSystem` to a `JumpSystem` which can be used to simulate the stochastic trajectories using the Gillespie algorithm.

````@example predator_prey_fig
````@example predator_prey_tutorial
jumpsys = convert(JumpSystem, rn)
#define the initial conditions, parameters, and time span
Expand Down Expand Up @@ -101,6 +103,9 @@ end
plt
````

save the plot
Plots.savefig(plt, "predator_prey_fig.png")

---

*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ using Plots
# ## Define the Lotka-Volterra model
# The Lotka-Volterra model describes the dynamics of predator-prey interactions in an ecosystem. It assumes that the prey population $U$ grows at a rate represented by the parameter $\alpha$ in the absence of predators, but decreases as they are consumed by the predator population $V$ at a rate determined by the interaction strength parameter, $\beta$. The predator population decreases in size if they cannot find enough prey to consume, which is represented by the mortality rate parameter, $\delta$.
# The corresponding ODE system reads
# ```math
# \begin{equation}
# \begin{aligned}
# \frac{\mathrm{d}U}{\mathrm{d} t} & = \alpha U - \beta U V,\\
# \frac{\mathrm{d}V}{\mathrm{d} t} & = \beta U V - \delta V,
# \end{aligned}\quad t\in (0, t_{\text{end}}).
# \end{equation}
# ```

rn = @reaction_network begin
@parameters α β δ
Expand Down Expand Up @@ -91,3 +93,5 @@ for (i, (mean_idx, var_idx)) in enumerate(zip(mean_idxs, var_idxs))
)
end
plt
# save the plot
# Plots.savefig(plt, "predator_prey_fig.png")

0 comments on commit 20e9076

Please sign in to comment.