Complete the code to fit a polynomial of degree 2 to data points.
p = polyfit(x, y, [1]);The third argument to polyfit specifies the degree of the polynomial. Here, degree 2 fits a quadratic curve.
Complete the code to evaluate the polynomial fit at points x_new.
y_fit = polyval(p, [1]);polyval.polyval evaluates the polynomial coefficients p at the points given by x_new.
Fix the error in the code to create a fit object for a linear fit.
f = fit(x, y, [1]);'linear' which is not a valid model name for fit.'poly2' which fits a quadratic, not linear.To fit a linear polynomial using fit, use the model name 'poly1'.
Fill both blanks to create a quadratic fit and plot it.
f = fit(x, y, [1]); plot(f, [2]);
'poly1' instead of 'poly2' for quadratic fit.'poly2' fits a quadratic polynomial. To plot the fit against new x-values, use x_new.
Fill all three blanks to create a cubic polynomial fit, evaluate it, and plot the results.
p = polyfit(x, y, [1]); y_fit = polyval(p, [2]); plot([3], y_fit, '-r');
Degree 3 fits a cubic polynomial. Evaluate at x_new and plot y_fit against x_new.