Serie 4 Aufgabe 3. Summen berechnen.
Skript berechnet mit Simpy Summen aus. Stellt sie mit Latex Formatierung (Summenzeichen = Summe) in einem interaktiven Fenster dar.
This commit is contained in:
parent
106c8af867
commit
799b18f586
28
reihen/serie_4_3.py
Normal file
28
reihen/serie_4_3.py
Normal file
@ -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))))
|
||||||
Loading…
x
Reference in New Issue
Block a user