Bird
0
0

You have noisy data vectors x and y. You want to fit a cubic polynomial and then predict the value at x = 7. Which sequence of MATLAB commands correctly does this?

hard📝 Application Q15 of 15
MATLAB - Numerical Methods
You have noisy data vectors x and y. You want to fit a cubic polynomial and then predict the value at x = 7. Which sequence of MATLAB commands correctly does this?
Ap = polyfit(x, y, 3); y_pred = p(7);
Bf = fit(x, y, 'poly2'); y_pred = feval(f, 7);
Cp = polyfit(y, x, 3); y_pred = polyval(p, 7);
Df = fit(x, y, 'poly3'); y_pred = feval(f, 7);
Step-by-Step Solution
Solution:
  1. Step 1: Choose correct fit function and degree

    Using fit with 'poly3' fits a cubic polynomial to x and y.
  2. Step 2: Predict value at x=7 using fit object

    Use feval(f, 7) or f(7) to get predicted y value from the fit object.
  3. Final Answer:

    f = fit(x, y, 'poly3'); y_pred = feval(f, 7); -> Option D
  4. Quick Check:

    fit with 'poly3' and feval predicts y at 7 [OK]
Quick Trick: Use fit with 'poly3' and feval to predict [OK]
Common Mistakes:
  • Swapping x and y in polyfit
  • Using wrong polynomial degree
  • Using poly2 instead of poly3 for cubic fit

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes