We use ODE solvers to find solutions to equations that describe how things change over time. RK45 and BDF are two common methods to do this accurately and efficiently.
Modeling how a population grows or shrinks over time.
Simulating the cooling of a hot object until it reaches room temperature.
Predicting the motion of a pendulum swinging back and forth.
Understanding chemical reactions that change concentrations over time.
exp(-2t) at t=0,1,2 = [1. 0.13533528 0.01831564] [OK]
Hint: Use exact solution exp(-2t) to check output array [OK]
Common Mistakes:
Confusing exponential decay with linear decay
Misreading t_eval points
Assuming RK45 returns integers
4. Identify the error in this code using BDF method:
from scipy.integrate import solve_ivp
def f(t, y):
return y - t**2 + 1
sol = solve_ivp(f, [0, 2], 0.5, method='BDF', t_eval=[0, 1, 2])
print(sol.y)
medium
A. Function f must take only one argument
B. Initial condition y0 should be a list or array, not a float
C. Method 'BDF' is not supported in solve_ivp
D. t_eval must be a numpy array, not a list
Solution
Step 1: Check initial condition format
The initial condition y0 must be an array-like object, even if single value, e.g., [0.5].
Step 2: Verify given y0 type
Here y0 is given as 0.5 (float), which is not array-like and causes error.
Step 3: Confirm other parameters
Function f has correct signature, method 'BDF' is valid, t_eval can be list or array.
Final Answer:
Initial condition y0 should be a list or array, not a float -> Option B
Quick Check:
y0 must be array-like [OK]
Hint: Always pass y0 as list or array, not single float [OK]
Common Mistakes:
Passing y0 as float instead of list
Thinking BDF is unsupported
Believing t_eval must be numpy array
5. You want to solve a stiff ODE system and compare solutions from RK45 and BDF methods. Which approach correctly compares their results at specific times?
hard
A. Use only RK45 since BDF is slow and ignore BDF results
B. Run RK45 without t_eval and BDF with t_eval, then compare sol.t arrays
C. Use solve_ivp with t_eval for both methods, then compare sol.y arrays at those times
D. Compare the initial conditions only, since methods differ internally
Solution
Step 1: Understand comparison requirements
To compare solutions, evaluate both methods at the same time points using t_eval.
Step 2: Use solve_ivp with t_eval for both
Passing t_eval ensures outputs have matching time points, so sol.y arrays can be directly compared.
Step 3: Reject incorrect approaches
Not using t_eval leads to different time points; ignoring BDF or comparing only initial conditions misses solution differences.
Final Answer:
Use solve_ivp with t_eval for both methods, then compare sol.y arrays at those times -> Option C
Quick Check:
Same t_eval for both = valid comparison [OK]
Hint: Use t_eval to get matching time points for comparison [OK]
Common Mistakes:
Not using t_eval for both methods
Comparing sol.t arrays instead of sol.y
Ignoring BDF results due to speed concerns
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.