0
0
SciPydata~10 mins

ODE solver methods (RK45, BDF) 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 ODE solver function from scipy.

SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Aodeint
Bode
Csolve_ivp
Dintegrate
Attempts:
3 left
💡 Hint
Common Mistakes
Using odeint which is older and less flexible.
Trying to import a non-existent function.
2fill in blank
medium

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

SciPy
def dydt(t, y):
    return [1] * y
Drag options to blanks, or click blank then click option'
A2
B-2
C-y
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Returning just -y instead of -2*y.
Returning a positive 2 instead of negative.
3fill in blank
hard

Fix the error in the code to solve the ODE using RK45 method.

SciPy
sol = solve_ivp(dydt, [0, 5], [1], method=[1])
Drag options to blanks, or click blank then click option'
A"bdf"
B"euler"
C"rk45"
D"RK45"
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'rk45' which causes an error.
Using unsupported method names like 'euler'.
4fill in blank
hard

Fill both blanks to solve the ODE using BDF method and print the solution at t=5.

SciPy
sol = solve_ivp(dydt, [0, [1]], [1], method=[2])
print(sol.y[0, -1])
Drag options to blanks, or click blank then click option'
A5
B10
C"RK45"
D"BDF"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong end time like 10.
Using lowercase method names.
5fill in blank
hard

Fill all three blanks to create a dictionary of solutions at specific times using RK45 method.

SciPy
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}
Drag options to blanks, or click blank then click option'
A"RK45"
B[0, 1, 2, 3]
C>=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Not passing t_eval to get solution at specific times.
Using wrong comparison operator in dictionary comprehension.