Compare commits
6 Commits
18d7e8cdb5
...
3484742925
| Author | SHA1 | Date | |
|---|---|---|---|
| 3484742925 | |||
|
|
dac54d71a2 | ||
|
|
5638b8aa38 | ||
| 76153f334e | |||
| 868566149d | |||
| 7eee7fc75b |
@ -1,2 +1,4 @@
|
|||||||
numpy
|
numpy==2.4.3
|
||||||
matplotlib
|
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()
|
||||||
|
# %%
|
||||||
61
src/serie_3.py
Normal file
61
src/serie_3.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# %%
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
# %%
|
||||||
|
print(60 * "-")
|
||||||
|
print(__file__)
|
||||||
|
print("Aufgabe 2. Interpolationspolynome gemäss NEWTON-Schema berechnen")
|
||||||
|
# punkte [[x0, x1, x2, xn], [y0, y1, y2, yn]]
|
||||||
|
punkte = [
|
||||||
|
[np.array([4, 8]), np.array([1, -1])],
|
||||||
|
[np.array([-1, 1, 2]), np.array([15, 5, 9])],
|
||||||
|
[np.array([-1, 0, 1, 2]), np.array([-5, -1, -1, 1])],
|
||||||
|
]
|
||||||
|
|
||||||
|
for punkt in punkte:
|
||||||
|
|
||||||
|
# Parameter
|
||||||
|
x_data = punkt[0]
|
||||||
|
y_data = punkt[1]
|
||||||
|
x_0 = x_data[0]
|
||||||
|
x_E = x_data[-1]
|
||||||
|
N = 201
|
||||||
|
lw = 3
|
||||||
|
fig = 1
|
||||||
|
|
||||||
|
# Berechnung
|
||||||
|
n = np.size(y_data)
|
||||||
|
TAB = np.block([[y_data], [np.zeros((n - 1, n))]])
|
||||||
|
c_data = np.zeros(n)
|
||||||
|
c_data[0] = y_data[0]
|
||||||
|
|
||||||
|
for i in range(1, n):
|
||||||
|
for j in range(1, n):
|
||||||
|
TAB[i][j] = (TAB[i - 1][j] - TAB[i - 1][j - 1]) / (
|
||||||
|
x_data[j] - x_data[j - i]
|
||||||
|
)
|
||||||
|
c_data[i] = TAB[i][i]
|
||||||
|
|
||||||
|
# Funktionen:
|
||||||
|
def p(x):
|
||||||
|
d = 1
|
||||||
|
y = c_data[0]
|
||||||
|
for k in range(1, n):
|
||||||
|
d = d * (x - x_data[k - 1])
|
||||||
|
y = y + c_data[k] * d
|
||||||
|
return y
|
||||||
|
|
||||||
|
# Daten
|
||||||
|
u_data = np.linspace(x_0, x_E, N)
|
||||||
|
v_data = p(u_data)
|
||||||
|
|
||||||
|
fh = plt.figure(fig)
|
||||||
|
plt.plot(u_data, v_data, linewidth=lw)
|
||||||
|
plt.plot(x_data, y_data, "o", linewidth=lw)
|
||||||
|
plt.xlabel(r"$x$")
|
||||||
|
plt.ylabel(r"$y$")
|
||||||
|
plt.grid(visible=True)
|
||||||
|
plt.axis("image")
|
||||||
|
|
||||||
|
print(60 * "-")
|
||||||
Loading…
x
Reference in New Issue
Block a user