Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 数值结果超出范围-Euler';s法_Python - Fatal编程技术网

Python 数值结果超出范围-Euler';s法

Python 数值结果超出范围-Euler';s法,python,Python,我似乎面临着一个问题,我写了一段代码,试图用Euler方法解决人口增长问题。我尝试过调整代码中的所有参数,但仍然遇到错误:(34,“数值结果超出范围”)。我怎样才能解决这个问题 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

我似乎面临着一个问题,我写了一段代码,试图用Euler方法解决人口增长问题。我尝试过调整代码中的所有参数,但仍然遇到错误:(34,“数值结果超出范围”)。我怎样才能解决这个问题

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")

谢谢!:)

输入是什么?请用您输入的实际值替换所有
input(…)
。出现错误的那一行是什么?@ForceBru我已对其进行了编辑,以便在这些值旁边对输入值进行注释lines@enzo第21行N+=h*f(N,t),然后返回第21行2@Jimbles,
在循环中打印(N)
,以查看
N
的值。我得到的值有
-7.5e+73
-1.69e+147
-8.54e+293