Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
MATLAB - Numerical Methods
What is wrong with this code?
x = [1 2 3 4]; y = [2 4 6]; p = polyfit(x, y, 1);
ADegree argument must be 2 or higher
BVectors x and y have different lengths
Cpolyfit cannot fit linear polynomials
Dpolyfit requires column vectors
Step-by-Step Solution
Solution:
  1. Step 1: Check vector lengths

    x has 4 elements, y has 3 elements; lengths differ.
  2. Step 2: Understand polyfit input requirements

    polyfit requires x and y vectors to be same length.
  3. Final Answer:

    Vectors x and y have different lengths -> Option B
  4. Quick Check:

    Equal length vectors needed for polyfit [OK]
Quick Trick: x and y must be same length vectors [OK]
Common Mistakes:
  • Ignoring vector length mismatch
  • Thinking polyfit auto-corrects lengths
  • Assuming column vectors required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes