Skip to content

Instantly share code, notes, and snippets.

@joseywoermann
Created December 19, 2021 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseywoermann/6070f817c84465af8ec59395773f6e99 to your computer and use it in GitHub Desktop.
Save joseywoermann/6070f817c84465af8ec59395773f6e99 to your computer and use it in GitHub Desktop.
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