0
0
SciPydata~10 mins

Solving ODEs (solve_ivp) in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the function used to solve ODEs.

SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Aode
Bodeint
Csolve_ivp
Dintegrate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'odeint' which is an older function.
Trying to import 'integrate' instead of the function.
Using 'ode' which is a different class.
2fill in blank
medium

Complete the code to define the ODE function for dy/dt = -2y.

SciPy
def ode_func(t, y):
    return [1] * y
Drag options to blanks, or click blank then click option'
A-2
B-y
C2
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Returning just -y instead of -2*y.
Returning 2*y which changes the sign.
Returning y without multiplication.
3fill in blank
hard

Fix the error in the solve_ivp call by filling the correct argument for the time span.

SciPy
solution = solve_ivp(ode_func, [1], [1], t_eval=[0, 1, 2])
Drag options to blanks, or click blank then click option'
A(0, 2)
B[0, 2]
C[0, 1]
D(1, 2)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a tuple for t_span.
Using incorrect time intervals like (1, 2).
Using only one time point.
4fill in blank
hard

Fill both blanks to create a dictionary of solution values at each time point.

SciPy
result = {t: y[1] for t, y in zip(solution.t, solution.[2])}
Drag options to blanks, or click blank then click option'
A[0]
By
Dy_values
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'y' instead of 'y[0]' which is an array.
Using 'y_values' which is not a valid attribute.
Not indexing the solution array.
5fill in blank
hard

Fill all three blanks to solve dy/dt = -3y with initial value 5 over [0, 4] and get values at t=0,2,4.

SciPy
def f(t, y):
    return [1] * y

sol = solve_ivp(f, [2], [[3]], t_eval=[0, 2, 4])
Drag options to blanks, or click blank then click option'
A-3
B(0, 4)
C5
D-2
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong coefficient like -2.
Using wrong time span like (0, 2).
Using wrong initial value.