# Contents

## Idea

Showing an easy way of doing predator-prey modeling in Sage. Right now it is a generic version

## Details

### Original Lotka-Volterra

This is the original Lotka-Volterra phase map for a non-dimensional form. This was posted on Marshall Hampon on the ask.sage site. Lotka-Volterra has many coarse “flaws” and has also been modified over time as we’ll see below. Dimensionless format of Lotka-Volterra. default for Sage ode_solver is to use runga-kutta-felhberg (4,5)

### Plot and Code T = ode_solver()
T.function = lambda t, y: [y-y*y, -y+y*y]
sol_lines = Graphics()
for i in srange(0.1,1.1,.1):
T.ode_solve(y_0=
[i,i],t_span=[0,10],num_points=1000)
y = T.solution
sol_lines += line([x for x in y], rgbcolor = (i,0,1-i))
show(sol_lines+point((1,1),rgbcolor=(0,0,0)), figsize = [6,6], xmax = 6, ymax = 6)


### Interactive and more realistic Lotka-Volterra

Here we enable choice of the exponential growth in the original Lotka-Volterra and logistic growth. We also added a parameter g which is used in both and k which is the scaled carrying capacity. See if you can find the fixed point for the latter (using the code below)?

It should look like this: def lv(g,k,growth):
Tg = ode_solver()
if growth == "Malthusian":
Tg.function = lambda t, y: [g*y*(1-y), (-1.0/g)*(1-y)]
else:
Tg.function = lambda t, y: [g*y*(1-y/k - y), (-1.0/g)*(1-y)]
sol_lines = Graphics()
for i in srange(0.1,1.1,.2):
Tg.ode_solve(y_0=[i,i],t_span=[0,10],num_points=1000)
y = Tg.solution
sol_lines += line([x for x in y], rgbcolor = (i,0,1-i))
return sol_lines

@interact
def _(g = (0.1,1.,0.1), k = (0.1,4.0,0.1), Growth=["Malthusian","Logistic"]):
show(lv(g,k,Growth),legend_label='Lv')


### Next step

We will look at cases where Lotka-Volterra might lead to Hopf bifurcation and also see if we can add the Allee effect