Challenge - 5 Problems
ODE Solver Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of RK45 solver on a simple ODE
What is the approximate value of y(2) when solving dy/dt = -2y with y(0) = 1 using RK45 method?
SciPy
from scipy.integrate import solve_ivp def fun(t, y): return -2 * y sol = solve_ivp(fun, [0, 2], [1], method='RK45') result = sol.y[0, -1] print(round(result, 3))
Attempts:
2 left
💡 Hint
Recall the exact solution is y(t) = exp(-2t). RK45 approximates this numerically.
✗ Incorrect
The exact solution at t=2 is exp(-4) ≈ 0.0183. RK45 with default tolerances and step sizes accurately approximates this to 0.018 when rounded to 3 decimals.
❓ Predict Output
intermediate2:00remaining
Output difference between RK45 and BDF on stiff ODE
Given the stiff ODE dy/dt = -1000y + 3000 - 2000 exp(-t), y(0)=0, what is the approximate value of y(0.1) using BDF method?
SciPy
import numpy as np from scipy.integrate import solve_ivp def stiff(t, y): return -1000*y + 3000 - 2000*np.exp(-t) sol = solve_ivp(stiff, [0, 0.1], [0], method='BDF') result = sol.y[0, -1] print(round(result, 2))
Attempts:
2 left
💡 Hint
BDF is good for stiff problems and will quickly approach the steady state.
✗ Incorrect
The stiff ODE solution at t=0.1 is close to 1.19 due to rapid initial change toward the quasi-equilibrium y ≈ 3 - 2*exp(-t). BDF handles stiffness well and produces this value.
🔧 Debug
advanced2:00remaining
Identify the error in ODE solver usage
What error will this code raise when trying to solve dy/dt = y with RK45 method?
from scipy.integrate import solve_ivp
def fun(t, y):
return y
sol = solve_ivp(fun, [0, 1], 1, method='RK45')
SciPy
from scipy.integrate import solve_ivp def fun(t, y): return y sol = solve_ivp(fun, [0, 1], 1, method='RK45')
Attempts:
2 left
💡 Hint
Check the type of initial condition y0 parameter.
✗ Incorrect
solve_ivp expects y0 as an array-like object (list or array). Passing an int causes ValueError.
❓ data_output
advanced2:00remaining
Number of time points returned by solve_ivp with dense output
Using solve_ivp with method='RK45' and dense_output=True on dy/dt = -y, y(0)=1 over [0,5], how many time points are in sol.t?
SciPy
from scipy.integrate import solve_ivp def fun(t, y): return -y sol = solve_ivp(fun, [0, 5], [1], method='RK45', dense_output=True) print(len(sol.t))
Attempts:
2 left
💡 Hint
RK45 adapts step size, so number of points is not fixed.
✗ Incorrect
The number of time points in sol.t depends on adaptive step size chosen by RK45, so it varies per run and problem.
🚀 Application
expert2:00remaining
Choosing solver method for a stiff system
You have a system of ODEs modeling chemical reactions with very fast and slow dynamics mixed. Which solver method is best to use in solve_ivp for stable and efficient results?
Attempts:
2 left
💡 Hint
Stiff systems require implicit solvers for stability.
✗ Incorrect
BDF is an implicit solver designed for stiff problems, providing stability and efficiency for mixed fast/slow dynamics.