Last active
March 26, 2022 15:47
-
-
Save shubham0204/88cba84f521e76a394a6e426e4610550 to your computer and use it in GitHub Desktop.
This file contains 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
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