-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename tutorial harmonic oscillators .py file
- Loading branch information
1 parent
96676de
commit 0ad0ddd
Showing
2 changed files
with
82 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# --- | ||
# jupyter: | ||
# jupytext: | ||
# formats: ipynb,py:light | ||
# text_representation: | ||
# extension: .py | ||
# format_name: light | ||
# format_version: '1.5' | ||
# jupytext_version: 1.16.1 | ||
# kernelspec: | ||
# display_name: .venv | ||
# language: python | ||
# name: python3 | ||
# --- | ||
|
||
# + [markdown] magic_args="[markdown]" | ||
# # Harmonic Oscillators | ||
# | ||
# In this tutorial, we demo how to generate data of harmonic oscillators. | ||
# - | ||
|
||
# %% | ||
import matplotlib.pyplot as plt | ||
|
||
from hamiltonian_flow.models.harmonic_oscillator import HarmonicOscillator | ||
|
||
# %% | ||
|
||
# %% | ||
n_periods = 3 | ||
n_samples_per_period = 200 | ||
|
||
# + [markdown] magic_args="[markdown]" | ||
# ## Simple Harmonic Oscillator | ||
# - | ||
|
||
# %% | ||
sho_omega = 0.5 | ||
|
||
sho = HarmonicOscillator(system={"omega": sho_omega}) | ||
|
||
# %% | ||
df_sho = sho(n_periods=n_periods, n_samples_per_period=n_samples_per_period) | ||
df_sho.head() | ||
|
||
# %% | ||
fig, ax = plt.subplots(figsize=(10, 6.18)) | ||
|
||
df_sho.plot(x="t", y="x", marker=".", ax=ax) | ||
|
||
ax.set_title(rf"Simple Harmonic Oscillator ($\omega = {sho_omega}$)") | ||
ax.set_ylabel(r"Displacement $x(t)$") | ||
ax.set_xlabel(r"$t$") | ||
|
||
# + [markdown] magic_args="[markdown]" | ||
# ## Damped Harmonic Oscillator | ||
# - | ||
|
||
# %% | ||
dho_systems = { | ||
"Underdamped": {"omega": 0.5, "zeta": 0.2}, | ||
"Critical Damped": {"omega": 0.5, "zeta": 1}, | ||
"Overdamped": { | ||
"omega": 0.5, | ||
"zeta": 1.2, | ||
}, | ||
} | ||
|
||
|
||
for s_name, s in dho_systems.items(): | ||
fig, ax = plt.subplots(figsize=(10, 6.18)) | ||
|
||
HarmonicOscillator(system=s)( | ||
n_periods=n_periods, n_samples_per_period=n_samples_per_period | ||
).plot(x="t", y="x", marker=".", ax=ax) | ||
|
||
ax.set_title( | ||
rf"{s_name} Harmonic Oscillator ($\omega = {s.get('omega')}$, $\zeta = {s.get('zeta')}$)" | ||
) | ||
ax.set_ylabel(r"Displacement $x(t)$") | ||
ax.set_xlabel(r"$t$") | ||
plt.show() |