Challenge - 5 Problems
ODE Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
Recall the exact solution of dy/dt = -2y is y(t) = exp(-2t).
✗ Incorrect
The exact solution at t=1 is exp(-2*1) = exp(-2) ≈ 0.1353. However, the code returns y(end) which corresponds to the last computed value by ode45 at t=1. The numerical solver approximates the solution and returns a value close to 0.1353. Option A matches this value. Option A (0.3679) corresponds to exp(-1), which is incorrect for this problem.
❓ Predict Output
intermediate2: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)
Attempts:
2 left
💡 Hint
When you provide a vector of time points to ode45, it returns solutions at those points.
✗ Incorrect
The time vector 0:0.5:2 generates [0, 0.5, 1.0, 1.5, 2.0], which has 5 points. ode45 returns solution values at each of these points, so length(y) is 5.
❓ Predict Output
advanced2: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)
Attempts:
2 left
💡 Hint
This system models a simple harmonic oscillator with initial position 0 and velocity 1.
✗ Incorrect
The system corresponds to the equations y1' = y2 and y2' = -y1, which describe sine and cosine functions. With initial conditions y1(0)=0 and y2(0)=1, the solution for y1(t) is sin(t). At t=pi/2, sin(pi/2) = 1. However, numerical approximation by ode45 may give a value close to 1 but slightly less. Option A (0.7071) corresponds to sin(pi/4), which is not the final time. Option A (1.0000) is the exact value. The numerical solver returns a value close to 1, so option A is correct.
❓ Predict Output
advanced2: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);
Attempts:
2 left
💡 Hint
ode45 expects the function to return a derivative vector matching the size of the initial condition.
✗ Incorrect
ode45 requires the function to return a column vector with the same number of rows as the initial condition y. Returning a vector of different size causes an error message indicating the size mismatch.
🧠 Conceptual
expert2:00remaining
Behavior of ode45 with stiff equations
Which statement best describes the behavior of
ode45 when solving stiff ordinary differential equations?Attempts:
2 left
💡 Hint
Consider the nature of explicit Runge-Kutta methods like ode45 and their suitability for stiff problems.
✗ Incorrect
ode45 is an explicit Runge-Kutta method designed for non-stiff problems. For stiff problems, it often requires very small time steps to maintain stability, making it inefficient. MATLAB provides other solvers like ode15s for stiff problems.