Ordinary Differential Equations
1. Review of Ordinary Differential Equations (ODE)
Intuition
An Ordinary Differential Equation (ODE) relates a function
ODEs are classified based on:
- Order: The highest derivative present.
- Linearity: Whether the equation can be written as a linear combination of the dependent variable and its derivatives.
Example
The solution is
Python Visualization
import numpy as np
import matplotlib.pyplot as plt
# Define the solution
def y(x, C):
return C * np.exp(-x)
# Plot
x = np.linspace(0, 5, 500)
C = 1
plt.plot(x, y(x, C), label='y = Ce^{-x}')
plt.title('Solution of y' + y = 0')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid()
plt.show()
2. Linear Equations
Intuition
A first-order linear ODE has the form:
The solution is obtained using an integrating factor:
Example
Solve
Python Visualization
from sympy import symbols, Function, Eq, exp, dsolve
# Define symbols
x = symbols('x')
y = Function('y')
# Define ODE
otde = Eq(y(x).diff(x) + y(x), x)
# Solve ODE
solution = dsolve(otde)
print(f"Solution: {solution}")
# Plot
C = 1
x_vals = np.linspace(0, 5, 500)
y_vals = x_vals - 1 + C * np.exp(-x_vals)
plt.plot(x_vals, y_vals, label='y = x - 1 + Ce^{-x}')
plt.title('Solution of y' + y = x')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid()
plt.show()
3. Second-Order Linear Equations
Intuition
A second-order linear ODE has the form:
The solution depends on the roots of the characteristic equation
- Distinct real roots:
. - Repeated root:
. - Complex roots:
.
Example
Solve
Python Visualization
# Define ODE
otde2 = Eq(y(x).diff(x, 2) - 3*y(x).diff(x) + 2*y(x), 0)
# Solve ODE
solution2 = dsolve(otde2)
print(f"Solution: {solution2}")
# Plot
C1, C2 = 1, 1
x_vals = np.linspace(0, 5, 500)
y_vals = C1 * np.exp(x_vals) + C2 * np.exp(2 * x_vals)
plt.plot(x_vals, y_vals, label='y = C1 e^x + C2 e^{2x}')
plt.title('Solution of y'' - 3y' + 2y = 0')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid()
plt.show()
4. Non-Homogeneous Linear Equations
Intuition
A second-order non-homogeneous ODE has the form:
The solution is:
where:
: Solution of the homogeneous equation. : Particular solution.
Example
Solve
Python Visualization
# Define ODE
otde3 = Eq(y(x).diff(x, 2) - y(x), exp(x))
# Solve ODE
solution3 = dsolve(otde3)
print(f"Solution: {solution3}")
# Plot
C1, C2 = 1, 1
x_vals = np.linspace(0, 5, 500)
y_vals = C1 * np.exp(x_vals) + C2 * np.exp(-x_vals) + 0.5 * x_vals * np.exp(x_vals)
plt.plot(x_vals, y_vals, label='y = C1 e^x + C2 e^{-x} + 0.5x e^x')
plt.title('Solution of y'' - y = e^x')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid()
plt.show()