这是您的问题的代码。假设从第一个小时开始到第一个小时结束,增长率为200%,这意味着它从一个值变为其值的3倍。然后从第二个小时的开始到结束的增长降低到较低的速率,依此类推。从最后一小时的开始到结束的增长率是2%,并且速率线性下降 - 即。费率是递减的算术级数。
此代码查找最终金额的最小完整小时数至少是初始金额的200倍。我不是一个笨拙的专家,所以我使用常规的Python循环计算整体增长,而不是使用numpy。
import numpy as np start_growth_rate = 2.00 # 200% as a decimal stop_growth_rate = 0.02 # 2% as a decimal target_total_growth = 200 # 200 times larger than the starting value calced_total_growth = 0 num_hours = 2 while calced_total_growth < target_total_growth: rates_array = np.linspace(start=start_growth_rate, stop=stop_growth_rate, num=num_hours) calced_total_growth = 1 for this_growth_rate in rates_array: calced_total_growth *= 1 + this_growth_rate num_hours += 1 print('Actual total growth rate = {} times over {} hours.'.format( calced_total_growth, num_hours - 1)) print('Growths = {}'.format(rates_array))
打印输出是
Actual total growth rate = 324.01866418570273 times over 9 hours. Growths = [ 2. 1.7525 1.505 1.2575 1.01 0.7625 0.515 0.2675 0.02 ]
最后的结果结束了 324 ,远远超过你的目标200.如果你把小时减少到只有8你得到
324
Actual total growth rate = 168.09849392178677 times over 8 hours. Growths = [ 2. 1.71714286 1.43428571 1.15142857 0.86857143 0.58571429 0.30285714 0.02 ]
这比你的目标200低,但比再使用一个小时更近。
使用9小时费率,在倒数第二个小时内实际超过200的目标。它的确切时间取决于你如何模拟从那个小时开始到结束的增长模式 - 小时内的增长与我的假设和我的代码无关。
另一组假设也是可能的 - 您给出的增长率是瞬时的,200x的目标不会在整数小时内发生。这里的解决方案更具数学性,但这是一个大纲。
如果我们让T是达到初始值的200倍的人口所需的时间。然后在时间上从2线性下降到0.02 T 增长率的公式 y 在时间 t 是
T
y
t
y'/y = 2 - (1.98 / T) * t
这是一个可分离的微分方程,初始条件为y(0)= 1。解决这个有解决方案
y = exp(2 * t - (0.99 / T) * t**2)
在Python语法中。由于我们希望在时间T结束目标200,我们得到
T = log(200) / 1.01 = 5.245858778760432
其中,对数是自然对数,最后一个值是近似值。所以人口函数的最终解决方案是
y = exp(2 * t - (0.9999 / log(200)) * t**2)
但是你在印刷阵列中想要的是增长率
y'/y = 2 - (1.9998 / log(200)) * t
它们大致显示在数组中
[2 - (1.9998 / log(200)) * t for t in range(6)]
评估为
[2.0, 1.622559416197654, 1.2451188323953077, 0.8676782485929615, 0.4902376647906155, 0.11279708098826946]
最后一个值不是0.02,因为增长在小时5点继续增长。(实际结束时间见上面的时间T。)