Ableitung mit Python/Sympy
This commit is contained in:
1 parent
69934aabb7
commit
e0f6db73a5
2 files changed
+68
No files matched your search
@@ -0,0 +1,32 @@
|
||||
# %%
|
||||
# Import SymPy for symbolic mathematics
|
||||
import sympy as sp
|
||||
|
||||
# Import display helpers to render LaTeX output in Jupyter/IPython
|
||||
from IPython.display import display, Math
|
||||
|
||||
# Define the symbolic variable x
|
||||
x = sp.symbols("x")
|
||||
|
||||
# List of functions to differentiate
|
||||
functions = [
|
||||
sp.exp(-x),
|
||||
x * sp.exp(x),
|
||||
(x + 2) * sp.exp(x),
|
||||
sp.exp(-(x**2)),
|
||||
(x + 1) * 2**x,
|
||||
(x + 1) * 3 ** -(x**2),
|
||||
]
|
||||
|
||||
|
||||
# Loop over each function, compute its derivative, and display both
|
||||
for func in functions:
|
||||
|
||||
# Differentiate with respect to x, then simplify the result
|
||||
derivativ = sp.simplify(sp.diff(func))
|
||||
|
||||
# Render f(x) and f'(x) as LaTeX; the double backslash (\\) creates a line break
|
||||
display(
|
||||
Math(r"f(x) = {} \\ f'(x) = {}".format(sp.latex(func), sp.latex(derivativ)))
|
||||
)
|
||||
# %%
|
||||
Reference in new issue
Block a user