From 799b18f586f1d3237f49f36f86e85ca5754e3406 Mon Sep 17 00:00:00 2001 From: git-sandro Date: Sun, 18 Oct 2026 11:17:41 +0200 Subject: [PATCH] Serie 4 Aufgabe 3. Summen berechnen. Skript berechnet mit Simpy Summen aus. Stellt sie mit Latex Formatierung (Summenzeichen = Summe) in einem interaktiven Fenster dar. --- reihen/serie_4_3.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 reihen/serie_4_3.py diff --git a/reihen/serie_4_3.py b/reihen/serie_4_3.py new file mode 100644 index 0000000..a1921bf --- /dev/null +++ b/reihen/serie_4_3.py @@ -0,0 +1,28 @@ +# %% +import sympy as sp +from IPython.display import display, Math + +# Define the symbolic variable +k = sp.symbols("k") + +# List of operations: each entry is [expression, (variable, lower_bound, upper_bound)] +operations = [ + [k, (k, 4, 10)], + [2 * k, (k, 4, 10)], + [k**3, (k, -2, 2)], + [1 / k, (k, 2, 4)], + [2**k, (k, 0, 4)], + [(-1) ** k, (k, 4, 9)], +] + +for operation in operations: + # Build the symbolic Sum object (Σ notation) + # *operation unpacks the list into separate arguments: expression, bounds + summenzeichen = sp.Sum(*operation) + + # Compute the actual numeric result of the summation + summe = sp.summation(*operation) + + # Convert both to LaTeX strings, join them with "=", + # wrap in Math() for rendering, and display in the interactive window + display(Math(r"{} = {}".format(sp.latex(summenzeichen), sp.latex(summe))))