Bird
0
0

What is the output of the following MATLAB code?

medium📝 Predict Output Q4 of 15
MATLAB - Numerical Methods
What is the output of the following MATLAB code?
p = [1 -6 11 -6];
r = roots(p);
disp(sort(r'));
A[0 0 0]
B[1 2 3]
C[1 -6 11]
D[6 11 6]
Step-by-Step Solution
Solution:
  1. Step 1: Identify polynomial and find roots

    The polynomial is x^3 - 6x^2 + 11x - 6, which factors as (x-1)(x-2)(x-3).
  2. Step 2: roots(p) returns roots and sort displays them sorted

    The roots are 1, 2, and 3, displayed as a row vector.
  3. Final Answer:

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

    roots of polynomial = [1 2 3] [OK]
Quick Trick: roots() returns polynomial zeros, sort for order [OK]
Common Mistakes:
  • Confusing coefficients with roots
  • Not sorting roots before display
  • Expecting coefficients as output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes