Skip to content

Instantly share code, notes, and snippets.

@shubham0204
Last active March 26, 2022 15:47
Show Gist options
  • Save shubham0204/88cba84f521e76a394a6e426e4610550 to your computer and use it in GitHub Desktop.
Save shubham0204/88cba84f521e76a394a6e426e4610550 to your computer and use it in GitHub Desktop.
import random
a = 0
b = 1
N = 1000
def f( x ):
return 2 * x**5
def uniform():
return random.uniform( a , b )
def compute():
M = f( uniform() )
for k in range( N ):
M += (( f( uniform() ) - M ) / (k + 1) )
return M * ( b - a )
integral = compute()
print( integral )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment