Serie 5 Aufgabe 3. Funktionen Plotten. Script plottet funktionen mit matplotlib

This commit is contained in:
Sandro Zimmermann 2026-10-26 13:53:24 +01:00
parent 799b18f586
commit a973b81707

View File

@ -0,0 +1,57 @@
#%%
import numpy as np
import matplotlib.pyplot as plt
fig = 0
lw = 3
functions = [
{
"x_0": 0.,
"x_E": 2.,
"N": 2,
"f": lambda x: 0.4 * x + 1,
},
{
"x_0": -2.,
"x_E": 2.,
"N": 129,
"f": lambda x: x ** 2,
},
{
"x_0": -6.,
"x_E": 2.,
"N": 129,
"f": lambda x: 2 ** x,
},
{
"x_0": 0.01,
"x_E": 10.,
"N": 129,
"f": lambda x: np.log(x)/np.log(10),
},
{
"x_0": -1,
"x_E": 4,
"N": 129,
"f": lambda x: 3 / (x + 2),
},
{
"x_0": 0,
"x_E": 4 * np.pi,
"N": 257,
"f": lambda x: 2 * np.sin(x),
},
]
for function in functions:
x_data = np.linspace(function["x_0"], function["x_E"], function["N"])
y_data = function["f"](x_data)
fh = plt.figure(fig)
fig += 1
plt.plot(x_data, y_data, linewidth=lw)
plt.xlabel(r"$x$")
plt.ylabel(r"$y$")
plt.grid(visible=True)
plt.axis("image")