Skip to content

Instantly share code, notes, and snippets.

@ueliwechsler
Last active January 26, 2020 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ueliwechsler/aa5017e98c21a6e540db57177f8c378e to your computer and use it in GitHub Desktop.
Save ueliwechsler/aa5017e98c21a6e540db57177f8c378e to your computer and use it in GitHub Desktop.
using DifferentialEquations
α = 1
β = 0.1
γ = 0.05
δ = 0.02
function lotka_voltera!(dx, x, p, t)
dx[1] = α*x[1] - β*x[1]*x[2]
dx[2] = δ*x[1]*x[2] - γ*x[2]
end
x0 = [10., # baboon
10] # cheetah
tspan = (0.0,100.0)
prob = ODEProblem(lotka_voltera!, x0, tspan)
sol = solve(prob)
using Plots
plot(sol.t, sol[1,:]; label="baboon")
plot!(sol.t, sol[2,:]; label="cheetah")
p = plot(sol);
p.series_list[1][:label] = "baboons";
p.series_list[2][:label] = "cheetahs"; p
xlabel!("time")
ylabel!("population size")
dir = @__DIR__
savefig(p, joinpath(dir,"test.emf"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment