Bird
0
0

What is the output of the following MATLAB code?

medium📝 Predict Output Q13 of 15
MATLAB - Numerical Methods
What is the output of the following MATLAB code?
p = [1 -3 2]; % Represents x^2 - 3x + 2
r = roots(p);
A[1 2]
B[3 2]
C[2 1]
D[-1 -2]
Step-by-Step Solution
Solution:
  1. Step 1: Identify the polynomial

    The vector p = [1 -3 2] represents the polynomial x^2 - 3x + 2.
  2. Step 2: Find roots of the polynomial

    Factoring: (x-1)(x-2) = 0 so roots are 1 and 2. MATLAB returns a column vector [2; 1], matching option [2 1].
  3. Final Answer:

    [2 1] -> Option C
  4. Quick Check:

    Roots of x^2-3x+2 = 1, 2 [OK]
Quick Trick: Roots are where polynomial equals zero [OK]
Common Mistakes:
  • Mixing up coefficient order
  • Forgetting roots are values of x
  • Assuming roots are negative

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes