Skip to content

Commit

Permalink
Merge branch 'diff-eq-subs-attempt'
Browse files Browse the repository at this point in the history
  • Loading branch information
beachdweller committed Jun 23, 2024
2 parents 3ed13e2 + b66c77c commit 43d0362
Showing 1 changed file with 148 additions and 7 deletions.
155 changes: 148 additions & 7 deletions 35_sympy/10_sympy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## 미분방정식<br>Differential Equations\n",
"## Differential Equations<br>미분방정식\n",
"\n"
]
},
Expand All @@ -1830,6 +1830,9 @@
"metadata": {},
"outputs": [],
"source": [
"import sympy as sym\n",
"\n",
"\n",
"f = sym.Function('f', real=True)\n",
"\n"
]
Expand Down Expand Up @@ -1869,7 +1872,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Free Vibration of a Mechanical System<br>기계시스템의 자유진동\n",
"### Free Vibration of a Mechanical System<br>기계시스템의 자유진동\n",
"\n"
]
},
Expand Down Expand Up @@ -1912,7 +1915,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Initial conditions<br>초기조건\n",
"#### **Initial** conditions<br>초기조건\n",
"\n"
]
},
Expand Down Expand Up @@ -2002,7 +2005,145 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Forced Vibration<br>강제진동\n",
"#### Substitution approach<br>대입법\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"A, B, zeta, omega, phi = sym.symbols('A B zeta omega phi', real=True)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f = sym.exp(zeta * t) * (A * sym.sin(omega * t) + B * sym.cos(omega * t))\n",
"f\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df = f.diff(t)\n",
"df\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df2 = df.diff(t)\n",
"df2\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"diff_eq = sym.simplify(sym.Eq(m * df2 + c * df + k * f, 0))\n",
"diff_eq\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"collected = sym.collect(sym.expand(diff_eq.lhs), [sym.exp(t*zeta)*sym.sin(omega * t), sym.exp(t*zeta)*sym.cos(omega * t)])\n",
"collected\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cos_term = collected.args[1]\n",
"sin_term = collected.args[0]\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"eq00 = sym.Eq(cos_term / (sym.exp(t*zeta)*sym.cos(omega * t)), 0)\n",
"eq00\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"eq01 = sym.Eq(sin_term / (sym.exp(t*zeta)*sym.sin(omega * t)), 0)\n",
"eq01\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"eq1 = sym.Eq(f.subs({t:0}), x0)\n",
"eq1\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"eq2 = sym.Eq(df.subs({t:0}), v0)\n",
"eq2\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sym.solve([eq00, eq01, eq1, eq2], [A, B, zeta, omega])\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Forced Vibration<br>강제진동\n",
"\n"
]
},
Expand Down Expand Up @@ -2091,8 +2232,8 @@
],
"metadata": {
"colab": {
"include_colab_link": true,
"provenance": []
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
Expand All @@ -2113,5 +2254,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 4
"nbformat_minor": 0
}

0 comments on commit 43d0362

Please sign in to comment.