Created
January 14, 2018 09:08
-
-
Save hzshang/a65d51640b042f9f8aa47b55f082b7aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from random import uniform | |
#calculate intergral | |
def integral(fun,a,b,N=10000): | |
sum=0 | |
for i in range(N): | |
sum=sum+fun(uniform(a,b)) | |
return sum/N*(b-a) | |
# test | |
print integral(lambda x : x + 1,0,1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment