Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to solve the ODE dy/dt = -2y using ode45.
MATLAB
tspan = [0 5]; y0 = 1; [t, y] = ode45(@(t,y) [1], tspan, y0);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '2*y' instead of '-2*y' changes the sign and the solution behavior.
Writing 'y-2' or 't*y' does not represent the given ODE.
✗ Incorrect
The function inside ode45 defines the derivative dy/dt = -2*y.
2fill in blank
mediumComplete the code to plot the solution y versus time t.
MATLAB
plot(t, [1]); xlabel('Time'); ylabel('Solution y');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Plotting t against t or tspan does not show the solution.
Using y0 plots only the initial value, not the solution.
✗ Incorrect
We plot the solution values y against time t.
3fill in blank
hardFix the error in the function definition for ode45 to solve dy/dt = y^2 - t.
MATLAB
odefun = @(t,y) [1]; [t, y] = ode45(odefun, [0 2], 0.5);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '**' causes syntax errors in MATLAB.
Changing the equation changes the problem.
✗ Incorrect
In MATLAB, '^' is used for power, so 'y^2 - t' is correct.
4fill in blank
hardFill both blanks to create a function handle for dy/dt = sin(t) - y.
MATLAB
odefun = @(t, y) [1] - [2]; [t, y] = ode45(odefun, [0 10], 1);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'cos(t)' instead of 'sin(t)' changes the equation.
Using 't' instead of 'y' changes the dependent variable.
✗ Incorrect
The derivative is dy/dt = sin(t) - y, so the function is 'sin(t) - y'.
5fill in blank
hardFill all three blanks to solve dy/dt = -3y + 2t and plot the result.
MATLAB
odefun = @(t, y) [1] * [2] + 2 * [3]; [t, y] = ode45(odefun, [0 4], 0); plot(t, y);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up variables y and t.
Using wrong coefficients changes the equation.
✗ Incorrect
The function is dy/dt = -3*y + 2*t, so blanks are '-3', 'y', and 't'.