```julia
using DifferentialEquations
using Plots
```

# Simple Harmonic Oscillator

The differential equation for a simple harmonic oscillator is given by 
\begin{equation}
    \ddot{x} + \omega_0^2x = 0 
\end{equation}
where $k=K/m$ is the reduced spring constant. 


```julia
force(dx, x, k, t) = -k*x
dx₀ = 1.0 
x₀ = 0.0 
k = 10.0
tspan = (0.0, 10.0)

prob = SecondOrderODEProblem(force, dx₀, x₀, tspan, k)
```




    [36mODEProblem[0m with uType [36mArrayPartition{Float64, Tuple{Float64, Float64}}[0m and tType [36mFloat64[0m. In-place: [36mfalse[0m
    timespan: (0.0, 10.0)
    u0: (1.0, 0.0)




```julia
sol = solve(prob); 
plot(sol, label=["Velocity" "Position"])
```




    

    



# Damped Harmonic Oscillator

We can introduce friction into the system via a new term. This leads us to the form: 
\begin{equation}
    \ddot{x} + \frac{\gamma}{2}\dot{x} + \omega_0^2x = 0 
\end{equation}
Friction works *against* the spring force... hence the positive coefficient $\gamma$. 


```julia
damped_force(dx, x, p, t) = -p[1]*x - p[2]*dx
dx₀ = 1.0 
x₀ = 0.0 
tspan = (0.0, 10.0)

p = [9.0, 1.0]
prob = SecondOrderODEProblem(damped_force, dx₀, x₀, tspan, p)
```




    [36mODEProblem[0m with uType [36mArrayPartition{Float64, Tuple{Float64, Float64}}[0m and tType [36mFloat64[0m. In-place: [36mfalse[0m
    timespan: (0.0, 10.0)
    u0: (1.0, 0.0)




```julia
sol = solve(prob);
plot(sol, label=["Velocity" "Position"])
```




    

    



there are 3 regimes of parameter values to consider: 
- Under damped: $\left(\dfrac{\gamma}{2}\right)^2 < \omega_0^2$
- Critically damped: $\left(\dfrac{\gamma}{2}\right)^2 = \omega_0^2$
- Over damped: $\left(\dfrac{\gamma}{2}\right)^2 > \omega_0^2$


```julia
using Interact # for widgets
```


<div style="padding: 1em; background-color: #f8d6da; border: 1px solid #f5c6cb; font-weight: bold;">
<p>The WebIO Jupyter extension was not detected. See the
<a href="https://juliagizmos.github.io/WebIO.jl/latest/providers/ijulia/" target="_blank">
    WebIO Jupyter integration documentation
</a>
for more information.
</div>




```julia
@manipulate for i ∈ 0.1:0.1:15
    p = [3.0, i]
    prob = SecondOrderODEProblem(damped_force, dx₀, x₀, tspan, p)
    sol = solve(prob);
    plot(sol, label=["Velocity" "Position"])
end
```




<div
    class="webio-mountpoint"
    data-webio-mountpoint="18356599718485989720"
>
    
</div>





```julia

```

c5be241e26ce30429d5cbcce265d772d956a0a03
ipynb
Jupyter Notebook
Data Generation.ipynb
john-waczak/SciML_SHO
180d46e9755e6a70f281086a373e183b57544275
MIT
Data Generation.ipynb
john-waczak/SciML_SHO
180d46e9755e6a70f281086a373e183b57544275
MIT
Data Generation.ipynb
john-waczak/SciML_SHO
180d46e9755e6a70f281086a373e183b57544275
MIT
Qwen/Qwen-72B
1. YES
2. YES