Skip to content

Commit

Permalink
rename tutorial harmonic oscillators .py file
Browse files Browse the repository at this point in the history
  • Loading branch information
emptymalei committed Feb 26, 2024
1 parent 96676de commit 0ad0ddd
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
8 changes: 0 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,3 @@ repos:
- id: isort
name: isort (python)
args: ["--multi-line", "3", "--profile", "black", "--treat-comment-as-code", "# %%", "--float-to-top"]
- repo: https://github.com/mwouts/jupytext
rev: v1.16.1
hooks:
- id: jupytext
args: [--sync, --pipe, black]
files: ^docs/tutorials/(.*\.py|.*\.ipynb)$
additional_dependencies:
- black==24.2.0
82 changes: 82 additions & 0 deletions docs/tutorials/harmonic_oscillator.py
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()

0 comments on commit 0ad0ddd

Please sign in to comment.