0
0
MATLABdata~20 mins

ODE solvers (ode45) in MATLAB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ODE Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of ode45 with a simple exponential decay
What is the output of the following MATLAB code snippet using ode45 to solve dy/dt = -2y with initial condition y(0) = 1 at t = 1?
MATLAB
odefun = @(t,y) -2*y;
[t,y] = ode45(odefun, [0 1], 1);
y(end)
A0.1353
B0.3679
C0.5000
D1.0000
Attempts:
2 left
💡 Hint
Recall the exact solution of dy/dt = -2y is y(t) = exp(-2t).
Predict Output
intermediate
2:00remaining
Number of output points from ode45 with specified time vector
Given the code below, how many points will the output y have?
MATLAB
odefun = @(t,y) y;
[t,y] = ode45(odefun, 0:0.5:2, 1);
length(y)
A6
B3
C5
D4
Attempts:
2 left
💡 Hint
When you provide a vector of time points to ode45, it returns solutions at those points.
Predict Output
advanced
2:00remaining
Output of ode45 solving a system of ODEs
What is the value of y(end,1) after running this code?
MATLAB
odefun = @(t,y) [y(2); -y(1)];
[t,y] = ode45(odefun, [0 pi/2], [0 1]);
y(end,1)
A1.0000
B0.0000
C-1.0000
D0.7071
Attempts:
2 left
💡 Hint
This system models a simple harmonic oscillator with initial position 0 and velocity 1.
Predict Output
advanced
2:00remaining
Error type when odefun returns wrong size output
What error does MATLAB produce when the function passed to ode45 returns a vector of incorrect size?
MATLAB
odefun = @(t,y) [y; y];
[t,y] = ode45(odefun, [0 1], 1);
ANo error, code runs successfully.
BIndex exceeds matrix dimensions.
CUndefined function or variable 'odefun'.
DError using ode45: The function must return a column vector of the same length as y.
Attempts:
2 left
💡 Hint
ode45 expects the function to return a derivative vector matching the size of the initial condition.
🧠 Conceptual
expert
2:00remaining
Behavior of ode45 with stiff equations
Which statement best describes the behavior of ode45 when solving stiff ordinary differential equations?
Aode45 is efficient and stable for stiff problems without any modifications.
Bode45 may require very small time steps and become inefficient for stiff problems.
Code45 automatically switches to a stiff solver when stiffness is detected.
Dode45 cannot solve stiff problems and will always produce errors.
Attempts:
2 left
💡 Hint
Consider the nature of explicit Runge-Kutta methods like ode45 and their suitability for stiff problems.