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?
x = [1 2 3 4]; y = [2 4 6 8]; p = polyfit(x, y, 1); disp(p);
A[1 2]
B[0 2]
C[2 1]
D[2 0]
Step-by-Step Solution
Solution:
  1. Step 1: Understand data and polyfit degree

    Data y = 2*x exactly fits line y = 2*x + 0, degree 1 polynomial.
  2. Step 2: polyfit returns coefficients highest degree first

    So p = [2 0] means 2*x + 0.
  3. Final Answer:

    [2 0] -> Option D
  4. Quick Check:

    polyfit output = [2 0] [OK]
Quick Trick: polyfit returns coefficients highest degree first [OK]
Common Mistakes:
  • Reversing coefficient order
  • Confusing slope and intercept
  • Expecting vector instead of coefficients

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes