FunctionRacerProblemsRace

Fish in the Lake

HardSciPyPython

The number of fish P in a lake changes at the rate dP/dt = r * P * (1 - P / K) - h: natural growth that slows as the lake fills toward K, minus a steady catch of h fish a year. Starting from P0 fish, return how many there are after T years. Solve it numerically with rtol=1e-9 and atol=1e-9. Answers within 0.01% are accepted.

Example 1

P0 100.0
r 0.5
K 1000.0
h 0.0
T 10.0
returns 942.8256184773629

With no catch the fish grow along an S-shaped curve toward 1000 and reach about 943 after 10 years.

Example 2

P0 500.0
r 1.0
K 1000.0
h 250.0
T 5.0
returns 500.0

At 500 fish the growth is exactly 250 a year, the same as the catch, so nothing changes.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More SciPy problems