function lotka_volterra!(du, u, p, t)
# Unpack the values so that they have clearer meaning
prey, pred = u
birth_prey, mort_prey, birth_pred, mort_pred = p
# Define the ODE
du[1] = (birth_prey - mort_prey * pred) * prey
du[2] = (birth_pred * prey - mort_pred) * pred
end
# define model parameters and initial conditions
θ = [1.1, 0.5, 0.1, 0.2]
u₀ = [1, 1]
tspan = 40
prob = ODEProblem(lotka_volterra!, u₀, (0.0, tspan), θ)
# plot phase space
p = plot(xlims=(0, 10), ylims=(0, 6),
xlabel = "Prey Population (1,000)", ylabel = "Predator Population (1,000)", leg = false)
function phase_plot(prob, u0, θ, p, tspan = 40)
_prob = ODEProblem(prob.f, u0, tspan, θ)
sol = solve(_prob, Vern9()) # Use Vern9 solver for higher accuracy
plot!(p, sol, idxs = (1, 2))
end
for x in 0:0.5:2.5
for y in 0:0.5:2.5
phase_plot(prob, [y, x], θ, p)
end
end
scatter!(p, [0, 2], [0, 2.2], color=:black)
plot!(size=(650, 550))