0
0
MATLABdata~10 mins

ODE solvers (ode45) in MATLAB - Interactive Code Practice

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

Complete 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'
A-2*y
B2*y
Cy-2
Dt*y
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.
2fill in blank
medium

Complete 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'
Ay0
Bt
Ctspan
Dy
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.
3fill in blank
hard

Fix 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'
Ay^2 - y
By**2 - t
Cy^2 - t
Dt - y^2
Attempts:
3 left
💡 Hint
Common Mistakes
Using '**' causes syntax errors in MATLAB.
Changing the equation changes the problem.
4fill in blank
hard

Fill 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'
Asin(t)
Bcos(t)
Cy
Dt
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.
5fill in blank
hard

Fill 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'
A-3
By
Ct
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up variables y and t.
Using wrong coefficients changes the equation.