The Language of Change
A Differential Equation (DE) describes how a state changes over time.
- Algebra solves for unknown numbers:
- Differential Equations solve for unknown functions:
In Computer Science, we rarely solve these analytically (by hand). We solve them numerically using algorithms like Euler’s Method or Runge-Kutta.
1. Classification & Definitions
Order: The highest derivative present in the equation.
- (First Order)
- (Second Order)
Linearity: An ODE is linear if the dependent variable and its derivatives appear to the first power and are not multiplied together.
- Linear:
- Non-Linear: (Because of )
2. First Order ODEs ()
A. Separable Equations
The simplest form. We move all ‘s to one side and all ‘s to the other.
B. Linear Equations (Integrating Factor)
Standard form:
Algorithm:
- Calculate the Integrating Factor:
- Multiply the entire equation by .
- The Left Hand Side (LHS) collapses via the Product Rule:
- Integrate both sides and solve for .
C. Exact Equations
If is “exact”, then there exists a potential function such that:
Solution: .
3. Second Order Linear ODEs ()
Typically used to model springs, circuits, and vibrations. Standard Form:
Part 1: Homogeneous ()
We assume the solution is of the form . This leads to the Characteristic Equation:
Solve for roots :
- Distinct Real Roots ():
- Repeated Real Root ():
- Complex Roots ():
Part 2: Non-Homogeneous ()
The general solution is .
- : The homogeneous solution (from Part 1).
- : The “Particular” solution.
Method of Undetermined Coefficients: Guess the form of based on :
| Term in | Guess for |
|---|---|
| or | |
| Polynomial |
4. The Laplace Transform ()
The engineer’s “Hack”. It turns Calculus problems (derivatives) into Algebra problems.
Definition:
Key Properties:
- Linearity:
- Differentiation: Turns derivatives into multiplication by .
Common Transforms Table:
Solving IVPs with Laplace
- Take of both sides of the ODE.
- Solve algebraically for .
- Use Partial Fractions to decompose .
- Take the Inverse Laplace to find .
5. Numerical Methods (CS Approach) 💻
When an ODE is impossible to solve by hand (which is 99% of real-world cases), we approximate.
Euler’s Method
The simplest approach. We use the tangent line to step forward in time.
- : Step size (e.g., 0.01).
- Error: (Global error is proportional to step size).
Runge-Kutta 4 (RK4)
The industry standard for simulations (Game physics, orbital mechanics). It samples the slope at 4 points to predict the next step.
Where:
Error: . Much more precise than Euler.
Linked Notes
- CPP-Ultimate-Guide - Implementing RK4 in C++.
- Linear-Algebra - Eigenvalues for Systems of ODEs.
- Physics-Simulation - Using ODEs for game engines.