All problems
Logistic ODE Euler Step
Problem
Take one explicit Euler step for the logistic ODE y' = r * y * (1 - y / k), where r is the growth rate and k is the carrying capacity.
Given the current population y and step size dt, return y + dt * r * y * (1 - y / k). Assume k != 0.
Hint
At y = 0 and y = k the growth term is zero, so the state does not move.
Test cases
case 1
in: [1,1,10,0.5]
expected: 1.45
case 2
in: [5,0.2,10,1]
expected: 5.5
case 3
in: [0,1,10,0.5]
expected: 0
case 4
in: [10,1,10,0.5]
expected: 10
case 5
in: [2,-1,10,0.5]
expected: 1.2
Starter codePython
def logistic_euler_step(y, r, k, dt):
# Your code here
pass5 test cases · run your code against them in the editor