close
import math
from time import localtime, strftime
def SimpsonRule(a, b, n):
sum = 0
for i in range(1,n,1):
Xi = a + ((b - a) / n) * i
if (i%2 == 0):
sum += 2 * f(Xi)
else:
sum += 4 * f(Xi)
sum += f(a) + f(b)
sum = sum * (b -a) / (3 * n)
return sum
def f(Xi):
return 1 / (Xi * Xi)
a = 1.0
b = 2.0
n = 60000000
print strftime("%H:%M:%S", localtime())
print SimpsonRule(a, b, n)
print strftime("%H:%M:%S", localtime())
全站熱搜
留言列表