Created
December 19, 2021 21:44
-
-
Save joseywoermann/6070f817c84465af8ec59395773f6e99 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 obersumme(n: int, f) -> None: | |
""" | |
Berechnet die Obersumme für `n` äquidistante Rechtecke mit der Funktion `f` im Intervall [0; 1] | |
`O(n) = 1/n * f(1/n) + 1/n * f(2/n) + 1/n * f(3/n) + ... + 1/n * f((n-1)/n) + 1/n * f(n/n)` | |
""" | |
term = 0 | |
for i in range(n + 1): | |
term += (1 / n) * f(i / n) | |
print(term) | |
def f(x: int) -> int: | |
return x * x | |
obersumme(2000, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment