Complete the code to import the function used to solve ODEs.
from scipy.integrate import [1]
The solve_ivp function from scipy.integrate is used to solve initial value problems for ODEs.
Complete the code to define the ODE function for dy/dt = -2y.
def ode_func(t, y): return [1] * y
The ODE is dy/dt = -2y, so the function returns -2 times y.
Fix the error in the solve_ivp call by filling the correct argument for the time span.
solution = solve_ivp(ode_func, [1], [1], t_eval=[0, 1, 2])
The t_span argument must be a tuple with start and end times, e.g., (0, 2).
Fill both blanks to create a dictionary of solution values at each time point.
result = {t: y[1] for t, y in zip(solution.t, solution.[2])}The solution values are stored in solution.y, which is an array. To get the value at the first variable, use y[0].
Fill all three blanks to solve dy/dt = -3y with initial value 5 over [0, 4] and get values at t=0,2,4.
def f(t, y): return [1] * y sol = solve_ivp(f, [2], [[3]], t_eval=[0, 2, 4])
The ODE is dy/dt = -3y, so return -3*y. The time span is (0, 4), and the initial value is 5.