Bird
0
0

What will be the output of the following MATLAB code?

medium📝 Predict Output Q4 of 15
MATLAB - Numerical Methods
What will be the output of the following MATLAB code?
f = @(t,y) 2*t;
[t,y] = ode45(f, [0 1], 0);
disp(y(end));
A0.5
B2
C1
DError due to wrong function
Step-by-Step Solution
Solution:
  1. Step 1: Understand the ODE and initial condition

    The ODE is dy/dt = 2*t with initial value y(0) = 0. The exact solution is y = t^2.
  2. Step 2: Evaluate solution at t=1

    At t=1, y = 1^2 = 1. So y(end) will be approximately 1.
  3. Final Answer:

    1 -> Option C
  4. Quick Check:

    Numerical solution at t=1 = 1 [OK]
Quick Trick: Integrate dy/dt=2t from 0 to 1 gives y=1 [OK]
Common Mistakes:
  • Confusing function output with derivative
  • Expecting initial value as output
  • Assuming error due to function handle

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes