42 lines
681 B
Python
42 lines
681 B
Python
# %%
|
|
# Python initialisieren
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
import scipy.integrate as ig
|
|
|
|
# Parameter
|
|
x_0 = 0.0
|
|
x_E = np.pi
|
|
N = 11
|
|
n = 5
|
|
pr = 6
|
|
lw = 3
|
|
fig = 1
|
|
|
|
# Funktion
|
|
f = lambda x: np.sin(x)
|
|
|
|
# Berechnungen
|
|
for k in range(0, n):
|
|
x_data = np.linspace(x_0, x_E, N)
|
|
y_data = f(x_data)
|
|
I = ig.trapezoid(y=y_data, x=x_data)
|
|
J = ig.simpson(y=y_data, x=x_data)
|
|
print(f"I = {I:#.16g}")
|
|
print(f"J = {J:#.16g}")
|
|
N *= 2
|
|
|
|
# Ausgabe
|
|
print(f"I = {I:#.{pr}g}")
|
|
print(f"J = {J:#.{pr}g}")
|
|
|
|
# Plot
|
|
fh = plt.figure(fig)
|
|
plt.plot(x_data, y_data, linewidth=lw)
|
|
plt.xlabel("x")
|
|
plt.ylabel("y")
|
|
plt.grid(visible=True)
|
|
plt.axis("image")
|
|
plt.show()
|
|
# %%
|