Skip to content

Commit

Permalink
clean up plot
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdsharpe committed Jan 30, 2024
1 parent 26f74df commit 03d5c5f
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
print(float(exact))

def get_approx(period=10, method="cubic"):
x_vals = np.cosspace(0, 1, n_samples).astype(float)
x_vals = np.linspace(0, 1, n_samples).astype(float)
f_vals = s.lambdify(
x,
f.subs(k, (n_samples - 1) / period),
Expand All @@ -40,8 +40,8 @@ def get_approx(period=10, method="cubic"):

import matplotlib.pyplot as plt
import aerosandbox.tools.pretty_plots as p
fig, ax = plt.subplots(2, 1)
for method in ["cubic", "simpson", "subgradient", "hybrid_simpson_cubic"]:
fig, ax = plt.subplots(2, 1, figsize=(6, 8))
for method in ["cubic", "simpson", "hybrid_simpson_cubic"]:
approxes = np.vectorize(
lambda period: get_approx(period, method=method)
)(periods)
Expand All @@ -51,4 +51,13 @@ def get_approx(period=10, method="cubic"):
plt.xlabel("Period [samples]")
ax[0].set_ylabel("Relative Error")
ax[1].set_ylabel("Approximation")
plt.sca(ax[1])
p.hline(
float(exact),
color="k",
linestyle="--",
label="Exact",
alpha=0.5
)

p.show_plot()

0 comments on commit 03d5c5f

Please sign in to comment.