0

I seem to be facing an issue with a code I wrote trying to solve a population growth problem using the Euler Method. I've tried adjusting all the parameters in the code, but I still am met with the error: (34, 'numerical result out of range'). How can I solve this problem?

def f(N,t):
    return a*N - b*N**2

a = float(input('birth rate = ')) #10
b = float(input('death rate = ')) #3
#bounds
c = 0.0
d = 100.0

# spacing for points
n = 1000
h = (d-c)/n

# initial population x(t=0)
N = float(input('initial population:')) #50

tpoints = arange(c,d,h)
xpoints = []
for t in tpoints:
    xpoints.append(N)
    N += h*f(N,t)

plot(tpoints, xpoints,'b-')
xlabel("time")
ylabel("population")

Thanks! :)

Jimbles
  • 19
  • 5
  • What's the input? Please replace all `input(...)` with the actual values you're inputting – ForceBru May 30 '21 at 21:22
  • What's the line that's giving the error? – enzo May 30 '21 at 21:24
  • @ForceBru I've edited it so the inputted values are commented right beside those lines – Jimbles May 30 '21 at 21:30
  • @enzo Line 21 N += h*f(N,t) which then returns to line 2 – Jimbles May 30 '21 at 21:32
  • @Jimbles, `print(N)` in the loop to see the values of `N`. I'm getting values like `-7.5e+73`, `-1.69e+147` and `-8.54e+293` – ForceBru May 30 '21 at 21:33
  • Does this answer your question? [OverflowError 'Numerical result out of range' when generating fibonacci numbers](https://stackoverflow.com/questions/12666600/overflowerror-numerical-result-out-of-range-when-generating-fibonacci-numbers) – enzo May 30 '21 at 21:39
  • @ForceBru yikes! something is definitely wrong with my equation – Jimbles May 30 '21 at 21:42

0 Answers0