mathematik1/reihen/serie_4_3.py
git-sandro 799b18f586 Serie 4 Aufgabe 3. Summen berechnen.
Skript berechnet mit Simpy Summen aus. Stellt sie mit Latex Formatierung (Summenzeichen = Summe) in einem interaktiven Fenster dar.
2026-10-18 11:17:41 +02:00

29 lines
871 B
Python

# %%
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))))