The Question:
following points can be expressed with an 8th-order polynomial. Determine the coefficients of the polynomial by using the least squares method and y values
for x = 3.25 and x = 1.85. Plot the polynomial.
x = [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0];
y = [0.2919 0.0050 0.1732 0.6418 0.9801 0.8770 0.4272 0.0444 0.0805];
My approach is below. I do not know if I did understand the question very well, so I am asking for a guide here. if it is correct
x = [1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0];y = [0.2919 0.0050 0.1732 0.6418 0.9801 0.8770 0.4272 0.0444 0.0805];fit = polyfit(x,y,8);x_fit = 0:1.0:5.0;y_fit = polyval(fit, x_fit);figure;plot(x,y);hold on;plot(x_fit, y_fit);grid on;xlabel('x');ylabel('y');legend('Data', 'Polyfit', 'Location', 'best');title(sprintf('x = 3.25 y is %.2f & x = 1.85 y is %.2f',polyval(fit,3.25),polyval(fit,1.85)))
Best Answer