```python
import sympy as sp

sp.init_printing()
```

# Math 5A -- Damped Harmoic Oscillator Example 


```python
# define symbols
gamma, omega_0, t, delta, F_0, alpha = sp.symbols(
    r"\gamma, \omega_0, t, \delta, F_0, \alpha"
)

# define function
x = sp.Function("x")(t)

# define differential equation
d = lambda x : sp.Derivative(x[0], t, x[1])
diff_eq = sp.Eq(
    d([x, 2]) + 2 * gamma * d([x, 1]) + omega_0**2 * x, F_0 * sp.exp(- alpha * t)
)
diff_eq
```


```python
# define the solution
x_sol = F_0 / sp.sqrt(omega_0**2 - gamma**2) / sp.sqrt(omega_0**2 + alpha**2 - 2 * alpha * gamma
    ) * sp.sin(sp.sqrt(omega_0**2 - gamma**2) * t - delta) * sp.exp(-gamma * t
    ) +  F_0 / (omega_0**2 + alpha**2 - 2 * alpha * gamma) * sp.exp(-alpha * t)
x_sol
```


```python
# you see how crazy it is
diff_eq.subs(x, x_sol)
```


```python
# doing the differential
diff_eq.subs(x, x_sol).doit()
```


```python
# for the left hand side
sp.simplify(diff_eq.subs(x, x_sol).lhs.doit())
```

Oh My God!! It's real! Those LHS craps is just $F_0 e^{-\alpha t}$.

8630afce33c9f8fdb7d90b933b54368d70f691c5
ipynb
Jupyter Notebook
Math HW 5A -- Damped Harmonic Oscillator Example.ipynb
jibanCat/math_homework
228fd61a84d03cdd8944d348e98662f1033e97ef
MIT
Math HW 5A -- Damped Harmonic Oscillator Example.ipynb
jibanCat/math_homework
228fd61a84d03cdd8944d348e98662f1033e97ef
MIT
Math HW 5A -- Damped Harmonic Oscillator Example.ipynb
jibanCat/math_homework
228fd61a84d03cdd8944d348e98662f1033e97ef
MIT
Qwen/Qwen-72B
1. YES
2. YES