Lesson 8 of 15
Systems of ODEs
Systems of ODEs
A single ODE describes one unknown. Many real problems involve multiple quantities that interact — requiring a system of ODEs:
We represent the state as a vector and the derivative function returns a vector too:
Vector Euler's Method
Exactly the same formula, applied component-wise:
def euler_system(f, t0, y0, t_end, n):
h = (t_end - t0) / n
t = t0
y = list(y0)
ys = [list(y)]
for _ in range(n):
dydt = f(t, y)
y = [yi + h * di for yi, di in zip(y, dydt)]
t += h
ys.append(list(y))
return ys
Example: Predator Growth
# Rabbit grows, fox grows proportionally
# dy1/dt = 2*y1, dy2/dt = y1
def f(t, y):
return [2*y[0], y[0]]
All future lessons use this vector pattern: simple harmonic motion, predator-prey, epidemic models.
Your Task
Implement euler_system(f, t0, y0, t_end, n) where f(t, y) returns a list of derivatives and y0 is a list of initial values. Return a list of state vectors.
Pyodide loading...
Loading...
Click "Run" to execute your code.