feat: Trapez und Simpson Integration. build: scipy zu requirements hinzugefügt
This commit is contained in:
parent
dac54d71a2
commit
3484742925
@ -1,3 +1,4 @@
|
||||
numpy
|
||||
matplotlib
|
||||
ipykernel
|
||||
numpy==2.4.3
|
||||
matplotlib==3.10.8
|
||||
ipykernel==7.2.0
|
||||
scipy==1.17.1
|
||||
41
src/scipy_integrate.py
Normal file
41
src/scipy_integrate.py
Normal file
@ -0,0 +1,41 @@
|
||||
# %%
|
||||
# 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()
|
||||
# %%
|
||||
Loading…
x
Reference in New Issue
Block a user