Created
February 26, 2020 17:20
-
-
Save BookOwl/596f6fadf87cf96be50ed37aa582032c 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
def reimann_l(f, a, b, n): | |
dx = (b - a)/n | |
area = dx * sum(f(a + i*dx) for i in range(n)) | |
return area | |
def reimann_r(f, a, b, n): | |
dx = (b - a)/n | |
area = dx * sum(f(a + i*dx) for i in range(1, n+1)) | |
return area | |
def H(x): return 1/x | |
n = 2 | |
a = reimann_l(H, 1, 2.7, n) | |
while a > 1: | |
n += 1 | |
a = reimann_l(H, 1, 2.7, n) | |
print(f"Integral of H from 1 to 2.7 is overestimated to be {a} with {n} subdivisions") | |
n = 2 | |
a = reimann_r(H, 1, 2.8, n) | |
while a < 1: | |
n += 1 | |
a = reimann_r(H, 1, 2.8, n) | |
print(f"Integral of H from 1 to 2.8 is underestimated to be {a} with {n} subdivisions") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment