Skip to content

Instantly share code, notes, and snippets.

@ctralie
Created February 15, 2023 15:30
Show Gist options
  • Save ctralie/f0a48a75fbaffb80b61d46c5a2c5f5d4 to your computer and use it in GitHub Desktop.
Save ctralie/f0a48a75fbaffb80b61d46c5a2c5f5d4 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "5a5b0995",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"N = 100\n",
"n = 2*np.pi*np.arange(N)/N\n",
"\n",
"n_frames = 50\n",
"ts = np.linspace(np.pi, 2*np.pi, n_frames)\n",
"\n",
"for i, t in enumerate(ts):\n",
" y = np.zeros(N)\n",
" for k in range(4):\n",
" f = 2*k+1\n",
" y += np.sin(f*t)*np.cos(f*n)/f - np.cos(f*t)*np.sin(f*n)/f\n",
" plt.clf()\n",
" plt.plot(y)\n",
" plt.plot([0, N], [0.6, 0.6])\n",
" plt.ylim([0, 1.2])\n",
" plt.title(\"t = {:.3f}\".format(t))\n",
" plt.savefig(\"{}.png\".format(i))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ff6c980",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
@ctralie
Copy link
Author

ctralie commented Feb 15, 2023

FourierSeriesTranslate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment