feat: spline, but doesn't work
This commit is contained in:
parent
f1fcf4f860
commit
204a8283f9
@ -1,6 +1,7 @@
|
||||
# %%
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import scipy.interpolate as ip
|
||||
|
||||
# %%
|
||||
print(60 * "-")
|
||||
@ -61,3 +62,53 @@ for punkt in punkte:
|
||||
print(60 * "-")
|
||||
|
||||
# %%
|
||||
print(75 * "-")
|
||||
print(__file__)
|
||||
print("Aufgabe 6. Polynom-Iterpolation vs. Cubic-Spline-Interpolation")
|
||||
print(75 * "-")
|
||||
|
||||
# Parameter
|
||||
x_data = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10])
|
||||
y_data = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 3.0, 3.0, 3.0, 3.0, 3])
|
||||
|
||||
x_0 = 0
|
||||
x_E = 11
|
||||
y_a = -1
|
||||
y_b = 5
|
||||
N = 501
|
||||
lw = 3
|
||||
sp = 0.2
|
||||
fig = 1
|
||||
tc_x = np.r_[x_0 : x_E + 1]
|
||||
tc_y = np.r_[y_a : y_b + 0.5 : 0.5]
|
||||
|
||||
# Berechnung
|
||||
po = ip.BarycentricInterpolator(x_data, y_data)
|
||||
cs = ip.CubicSpline(x_data, y_data)
|
||||
|
||||
# Daten
|
||||
u_data = np.linspace(x_0, x_E, N)
|
||||
v_data = po(u_data)
|
||||
w_data = cs(u_data)
|
||||
|
||||
# Plot
|
||||
[fh, ax] = plt.subplot(2, 1)
|
||||
ax[0].plot(u_data, v_data, linewidth=lw)
|
||||
ax[0].plot(x_data, y_data, "o", linewidth=lw)
|
||||
ax[0].set_xlabel(r"$x$")
|
||||
ax[0].set_ylabel(r"$y$")
|
||||
ax[0].set_xticks(tc_x)
|
||||
ax[0].set_yticks(tc_y)
|
||||
ax[0].grid(visible=True)
|
||||
ax[0].axis([x_0, x_E, y_a, y_b])
|
||||
ax[1].plot(u_data, w_data, linewidth=lw)
|
||||
ax[1].plot(x_data, y_data, "o", linewidth=lw)
|
||||
ax[1].set_xlabel(r"$x$")
|
||||
ax[1].set_ylabel(r"$y$")
|
||||
ax[1].set_xticks(tc_x)
|
||||
ax[1].set_yticks(tc_y)
|
||||
ax[1].grid(visible=True)
|
||||
ax[1].axis([x_0, x_E, y_a, y_b])
|
||||
plt.subplots_adjust(hspace=sp)
|
||||
|
||||
# %%
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user