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 solve_ivp with simple ODE
What is the output array of y values when solving dy/dt = 2t with initial condition y(0)=1 over t in [0,1] using solve_ivp with default settings?
SciPy
from scipy.integrate import solve_ivp def ode(t, y): return 2*t sol = solve_ivp(ode, [0, 1], [1]) print(sol.y[0])
Attempts:
2 left
💡 Hint
Recall the analytical solution y = t^2 + 1 and that solve_ivp samples points automatically.
✗ Incorrect
The ODE dy/dt = 2t integrates to y = t^2 + C. With y(0)=1, C=1. The solver returns approximate y values at chosen t points, close to t^2 + 1.
❓ data_output
intermediate1:30remaining
Number of time points in solve_ivp solution
Using solve_ivp to solve dy/dt = -3y with y(0)=5 over [0,1], how many time points does the solution contain by default?
SciPy
from scipy.integrate import solve_ivp def ode(t, y): return -3*y sol = solve_ivp(ode, [0, 1], [5]) print(len(sol.t))
Attempts:
2 left
💡 Hint
Check the default number of points solve_ivp evaluates if no t_eval is given.
✗ Incorrect
By default, solve_ivp chooses about 10 time points adaptively unless t_eval is specified.
🔧 Debug
advanced1:30remaining
Identify the error in solve_ivp call
What error will this code raise?
from scipy.integrate import solve_ivp
def f(t, y):
return t - y
sol = solve_ivp(f, 0, [1])
SciPy
from scipy.integrate import solve_ivp def f(t, y): return t - y sol = solve_ivp(f, 0, [1])
Attempts:
2 left
💡 Hint
Check the type and format of the second argument to solve_ivp.
✗ Incorrect
The second argument t_span must be a tuple or list with two elements (start and end). Passing 0 (int) causes ValueError.
🚀 Application
advanced2:00remaining
Predict final value of logistic growth model
Using solve_ivp to solve the logistic growth ODE dy/dt = 0.5*y*(1 - y/10) with y(0)=1 over [0, 10], what is the approximate value of y at t=10?
SciPy
from scipy.integrate import solve_ivp def logistic(t, y): return 0.5 * y * (1 - y / 10) sol = solve_ivp(logistic, [0, 10], [1], t_eval=[10]) print(sol.y[0][0])
Attempts:
2 left
💡 Hint
The logistic model approaches the carrying capacity 10 over time.
✗ Incorrect
The logistic growth approaches the carrying capacity 10, so y at t=10 is close to 10 but slightly less.
🧠 Conceptual
expert2:30remaining
Effect of changing 'method' parameter in solve_ivp
Which statement correctly describes the effect of changing the 'method' parameter in solve_ivp from 'RK45' to 'BDF'?
Attempts:
2 left
💡 Hint
Consider the difference between explicit and implicit solvers and stiffness of ODEs.
✗ Incorrect
'BDF' is an implicit solver designed for stiff ODEs, while 'RK45' is an explicit Runge-Kutta method suited for non-stiff problems.