Bird
0
0

What will be the output of this MATLAB code?

medium📝 Predict Output Q5 of 15
MATLAB - Numerical Methods
What will be the output of this MATLAB code?
p = [1 0 -4];
val = polyval(p, 2);
disp(val);
A-4
B4
C0
D8
Step-by-Step Solution
Solution:
  1. Step 1: Understand polynomial and evaluation point

    Polynomial is x^2 - 4, evaluated at x=2.
  2. Step 2: Calculate value

    polyval(p, 2) = 2^2 - 4 = 4 - 4 = 0.
  3. Final Answer:

    0 -> Option C
  4. Quick Check:

    polyval(p, 2) = 0 [OK]
Quick Trick: Calculate polynomial value by substituting x [OK]
Common Mistakes:
  • Forgetting to square 2
  • Mixing coefficient order
  • Using roots() instead of polyval()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes