Exercises_MarkusSchmidt/sheet2/C/main.py
2025-10-22 00:11:42 +02:00

28 lines
533 B
Python

import numpy as np
import matplotlib.pyplot as plt
def u(x, p):
if p == 0:
return x
else:
return (np.exp(p*x)-1)/(np.exp(p)-1)
x = np.linspace(0, 1, 200)
t = np.linspace(-1, 1, 15)
p_values = 50 * np.sign(t)*np.power(t,2) #make more values around 0
cmap = plt.cm.rainbow
plt.figure()
for p, color in zip(p_values, cmap(np.linspace(0, 1, len(p_values)))):
plt.plot(x, u(x, p), color=color, linewidth=2, label=f"p={p:.0f}")
plt.xlabel("x")
plt.ylabel("u(x)")
plt.legend()
plt.grid(True)
plt.show()