# Can someone redirect me to a good tutorial for my task?

I am sadly one of those students who won’t be recieving any lectures in the next few weeks, and my teachers have told me to look online for help. So here I go.
I am stuck with a paper which is part of an later exam.

Make a program that can simulate populations of foxes (predators) and rabbits (pray).
The populations can be calculated one time step at a time :
Rabbit(tn+1) = Rabbit(tn) * (1 + a – b * Rabbit(tn) – c * Fox(tn))
Fox(tn+1) = Fox(tn) * (1 – d + e * Rabbit(tn) – f * Fox(tn)))
Try a = 0.1 b = 0.00002 c = 0.01 d = 0.01 e = 0.00002 f = 0.0001
(b and f represent damping)
Initial amount of rabbits = Rabbit(t0) = 500
Initial amount of foxes = Fox(t0) = 10
Time from 0 to 400
Make a graph showing how the populations changes in time.
What are the steady state values ?
Try also Initial amount of rabbits = Rabbit(t0) = 600
Initial amount of foxes = Fox(t0) = 16
You can experiment with the parameters and initial populations.
Remember that if a population at a time is 0 (or negative) the species is extinct.

I have made a calculator before in Python, but this seems to be a different task. The fact that I am dyscalculic does not help sadly =/
Do you know of any tutorials that cover something similar to this? I have no idea what to look for.

You need a bit of math here
The population is given in the form of a sequence.

You can try to look at this:
https://www.mathsisfun.com/algebra/sequences-series.html

Once you get the math, the implementation in any programming language should be nothing new

Hi Again.
So I managed to get some help with the code, but I have one issue.
I am getting an error “TypeError: unsupported operand type(s) for *: ‘function’ and ‘float’” at this line:

``````        foxtnplus1 = foxt0 * (1-d + e * rabt0-f * foxt0)
return[rabitnplus1, foxtnplus1]
``````

Here is the whole code.
What did I do wrong?

``````#Rabbit(tn+1) = Rabbit(tn) * (1 + a – b * Rabbit(tn) – c *  Fox(tn))
#Fox(tn+1) = Fox(tn) * (1 – d + e * Rabbit(tn) – f *  Fox(tn)))
import math
import random
import numpy as np
from random import randint
from scipy.integrate import odeint
import matplotlib.pyplot as plt

rabt0 = float(input("Initial amount of rabbits: "))
foxt0 = float(input("Initial amount of foxes: "))

a = 0.1
b = 0.00002
c = 0.01
d = 0.01
e = 0.00002
f = 0.0001

def f(y,t):

rabitnplus1 = rabt0 * (1 + a-b * rabt0-c *  foxt0)

foxtnplus1 = foxt0 * (1-d + e * rabt0-f * foxt0)
return[rabitnplus1, foxtnplus1]

y0 = [rabt0, foxt0]   #initialized vector
t = np.linspace(0, 25., 20000)   #time

soln = odeint(f, y0, t)
rab = soln[:, 0]
fox = soln[:, 1]

plt.figure()
plt.plot(t, rab, 'b', label = "Rabbits")
plt.plot(t, fox, 'r', label = "Foxes")
plt.plot(rab, fox)
plt.xlabel('Time')
plt.ylabel('Population Sizes')
plt.title('Populations of Rabbits and Foxes')
plt.legend(loc = 0)
plt.show()
``````

Hello there.

You have a variable `f`, as well as a function `f`. You need to use different names, in order to ensure there is no confusion.

The error is telling you, you cannot multiply function `f` by `foxt0`, or subtract `f` from `rabt0`.

Also, why does your function `f` have two unused parameters?

Hope this helps