Python:集成了100个函数和集成变量

时间:2017-02-22 18:54:38

标签: python scipy integrate

我想计算表格的一个整数:large integral

我正在努力在python中实现它。有没有一种程序化的方法来实现这一目标?我尝试用几个for循环来做这个但是我坚持错误SystemError: too many statically nested blocks

fs = {}
for i in range(100):
   fs[i] = lamda x: x*i

for x1 in np.arange(0,1,.01):
   for x2 in np.arange(0,1,.01):
      ....
          for x100 in np.arange(0,1,.01):
             for i in range(100):
                exec("summ+= fs[i](x%i"%i)

1 个答案:

答案 0 :(得分:1)

当然很慢: " for i in range(100)" (1)部分达到100 * 100 * 100 * ... * 100(100' * 100' s)= 100 ^ 100;人们说n ^ 2很糟糕...... 无论如何,我会这样做:

- Put 100 values initialized with 0 into a list.
 - for i = 0 to 100 ^ 100:
   - go through the list and use the k-th value as the parameter for the k-th function. do the summing thing
   - Add 0.1 to the n-th value in the list; 
     if this value is now == 1; set it to 0 and go to the (n+1)-th value and repeat this procedure until you reach the end of the list or one value is < 1. 
     Start with the first value in the list.
now you have your sum.