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())

Posted by give at 痞客邦 PIXNET Comments(0) Trackback(1) Hits(65)


open trackbacks list Trackbacks (1)

  • .

    Bookmark This

Comments (0)

Post Comment

Comment Permissions: Allow commenting

Leave Comment

*Name/Nickname
E-mail
Personal Website
Comment Title
*Comment
* Private Comment