Chapter 1: Differential Equations - IntroductionΒΆ
The Language of ChangeΒΆ
Differential equations describe how things change in the world.
What is a Differential Equation?ΒΆ
An equation involving:
A function (e.g., temperature T(x,t))
Its derivatives (e.g., dT/dt, dΒ²T/dxΒ²)
Example: Newtonβs Second Law $\( F = ma = m\frac{d^2x}{dt^2} \)$
This relates force to the second derivative of position!
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
sns.set_style('whitegrid')
plt.rcParams['figure.figsize'] = (14, 10)
np.set_printoptions(precision=3, suppress=True)
Types of Differential EquationsΒΆ
Ordinary Differential Equations (ODEs)ΒΆ
One independent variable (usually time t)
Example: Exponential growth/decay $\( \frac{dP}{dt} = kP \)$
Solution: P(t) = Pβe^(kt)
Partial Differential Equations (PDEs)ΒΆ
Multiple independent variables (e.g., space x and time t)
Example: Heat equation $\( \frac{\partial T}{\partial t} = \alpha \frac{\partial^2 T}{\partial x^2} \)$
def exponential_growth():
"""Visualize exponential growth solution."""
t = np.linspace(0, 5, 100)
fig, axes = plt.subplots(1, 2, figsize=(14, 6))
# Different growth rates
ax1 = axes[0]
for k in [0.5, 1.0, 1.5, 2.0]:
P = np.exp(k * t)
ax1.plot(t, P, linewidth=2, label=f'k = {k}')
ax1.set_xlabel('Time t', fontsize=12)
ax1.set_ylabel('Population P', fontsize=12)
ax1.set_title('Exponential Growth: dP/dt = kP', fontweight='bold')
ax1.legend()
ax1.grid(True, alpha=0.3)
# Decay
ax2 = axes[1]
for k in [-0.5, -1.0, -1.5]:
P = np.exp(k * t)
ax2.plot(t, P, linewidth=2, label=f'k = {k}')
ax2.set_xlabel('Time t', fontsize=12)
ax2.set_ylabel('Population P', fontsize=12)
ax2.set_title('Exponential Decay', fontweight='bold')
ax2.legend()
ax2.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()
print("Solution: P(t) = Pβ e^(kt)")
print(" k > 0: Growth")
print(" k < 0: Decay")
exponential_growth()
Why Differential Equations MatterΒΆ
Natural PhenomenaΒΆ
Physics: Motion, heat, waves, quantum mechanics
Biology: Population dynamics, disease spread
Chemistry: Reaction rates
Engineering: Circuits, control systems
The PowerΒΆ
Once you write down the differential equation:
It captures the rule of how things change
Solving it predicts the future
It works for any initial condition!
Next: The heat equation - a beautiful PDE!