Complete the code to import the ODE solver function from scipy.
from scipy.integrate import [1]
odeint which is older and less flexible.The solve_ivp function is the modern ODE solver in scipy that supports methods like RK45 and BDF.
Complete the code to define the ODE function for dy/dt = -2y.
def dydt(t, y): return [1] * y
The ODE is dy/dt = -2y, so the function returns -2 times y.
Fix the error in the code to solve the ODE using RK45 method.
sol = solve_ivp(dydt, [0, 5], [1], method=[1])
The method name is case-sensitive and should be "RK45" with uppercase letters.
Fill both blanks to solve the ODE using BDF method and print the solution at t=5.
sol = solve_ivp(dydt, [0, [1]], [1], method=[2]) print(sol.y[0, -1])
The time interval ends at 5, and the method for stiff problems is "BDF".
Fill all three blanks to create a dictionary of solutions at specific times using RK45 method.
times = [0, 1, 2, 3] sol = solve_ivp(dydt, [0, 3], [1], method=[1], t_eval=[2]) results = {t: y for t, y in zip(sol.t, sol.y[0]) if t [3] 0}
Use "RK45" as method, provide t_eval as the list of times, and filter times greater or equal to 0.