Python:整合 100 个函数和整合变量
Python: integrate across 100 functions and integration variables
我想计算以下形式的积分:。
我正在努力在 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)
当然慢了:
"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.
我想计算以下形式的积分:
我正在努力在 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)
当然慢了: "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.