Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/inventwithdean/damped_harmonic_oscillator

A solution to Spring-Mass-Damper using Forward Euler Integration
https://github.com/inventwithdean/damped_harmonic_oscillator

differential-equations dynamical-systems euler-integration

Last synced: 4 days ago
JSON representation

A solution to Spring-Mass-Damper using Forward Euler Integration

Awesome Lists containing this project

README

        

# 🌊 Damped Harmonic Oscillator Integration
*A beautiful dance of physics and mathematics* ✨

Based on Steve Brunton's amazing lecture: [Second-Order ODE: Spring-Mass-Damper](https://youtu.be/r1eWerqrcqo) 🎓

## 🧮 The Beautiful Theory
The damped harmonic oscillator is like a poetry in physics, described by this elegant equation:

$$m\frac{d^2x}{dt^2} + c\frac{dx}{dt} + kx = 0$$

What's dancing in this equation? 🩰
- m = mass (our main character)
- c = damping coefficient (the resistance)
- k = spring constant (the restoring force)
- x = position (where we are)
- dx/dt = velocity (how fast we're moving)
- d²x/dt² = acceleration (how our speed changes)

### 🔄 State Space Magic
Here's where it gets interesting! We can transform our 2nd order ODE into two 1st order ODEs using the state space sorcery ✨

Let's say $x$ be the position and $v = \dot{x}$ be the velocity.

And voilà! Our system becomes this beautiful matrix:
$$\begin{bmatrix} \dot{x} \\ \dot{v} \end{bmatrix} = \begin{bmatrix} 0 & 1 \\ -\omega^2 & -\zeta \end{bmatrix} \begin{bmatrix} x \\ v \end{bmatrix}$$

The magical ingredients 🪄:
- $\omega = \sqrt{\frac{k}{m}}$ (natural frequency - the system's heartbeat 💓)

- $\zeta = {\frac{c}{m}}$ (damping ratio - how quickly the dance fades 🌙)

## 📊 Understanding Our Creation

![output](https://github.com/user-attachments/assets/8459782d-6dfb-4981-8774-8c9e751d3412)

### 📈 Time Domain Plot
Watch the beautiful dance unfold:
- 🔵 Blue line: Position gracefully oscillating and settling
- ❤️ Red dashed line: Velocity leading the dance
- Both gradually calm down, like waves on a peaceful shore 🌊

### 🌀 Phase Space Plot (The Most Beautiful Part!)
This is where mathematics meets art:
- A mesmerizing spiral in position-velocity space 🌌
- Each loop tells a story of one complete oscillation ⭕
- The journey to equilibrium is like a leaf gently falling 🍃
- The spiral's shape reveals the system's character 🎭

### 🎯 Key Insights
1. 🎯 Matrix multiplication → instant rates of change
2. ⏱️ Small time steps → future prediction
3. 📐 Smaller steps = better accuracy (but more computation!)
4. ⚖️ Newton's F = ma holds every single moment!

## 🌟 The Beauty of Physics
This simple system shows us how nature works in perfect harmony:
- Energy gradually dissipates 📉
- Oscillations find their natural rhythm 🎵
- Mathematics predicts reality with stunning accuracy ✨

## 📚 Want to Learn More?
- 🎥 Watch Steve Brunton's amazing Spring-Mass-Damper: [Video Link](https://youtu.be/r1eWerqrcqo)
- 📺 Full playlist for more Differential Equations: [Differential Equations and Dynamical Systems](https://youtube.com/playlist?list=PLMrJAkhIeNNTYaOnVI3QpH7jgULnAmvPA&feature=shared)

---
*Remember: In every equation, there's a story. In every oscillation, there's a dance. And in every simulation, there's a bit of magic!* ✨🪄