Script for working out exponential limit within a set range

牧云@^-^@ 提交于 2021-01-28 06:23:51

问题


In the image above column B is multiples of A1 and column C is C = C + B (working down the rows)

I worked out that in order for C for be 50 in 20 rows A1 has to be 0.2631579 but I'd like to be able to simplify that to a function that will return a list: list = exp(50, 20).

I'm not sure about the terminology of such a script so researching beforehand didn't really bring anything up sorry.


回答1:


Well based on your problem statement, we know that:

Bn=(n-1)×a; and Cn=(n-1)×n×a/2 (here a is the value for A1).

So we only have to solve a for C20=50. Or more genic: Cn=m. This is simply: a = 2×m/(n×(n-1)).

So the function is simply:

def find_threshold(m,n):
    return 2.0*m/(n*(n-1))

For your sample input, the lower bound is:

>>> find_threshold(50,20)
0.2631578947368421

If you plug in this value in the Excel sheet, you will obtain 50 (although there can be small rounding errors). Given we assume calculations on the numbers are done in constant time, this script works in constant time as well (O(1)) so it is quite fast (even if the row number, etc. would be huge).



来源:https://stackoverflow.com/questions/43140213/script-for-working-out-exponential-limit-within-a-set-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!