POLYNOMIAL CURVE FITTING For the following experimental data-set of (x,y) pair-values

  1. POLYNOMIAL CURVE FITTING For the following experimental data-set of (x,y) pair-values x=[0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1] y=[-0.45 1.98 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.20] Get the 2
    order polynomial that best fits these data (use least-square fitting methods). Repeat the previous exercise for 3
    and 10
    order polynomials. Plot in a single graph the experimental results and the obtained 2
    , 3
    and 10
    order polynomials. Notes: Matlab functions: inv, “”, eig, cond, roots, poly, conv, deconv, polyder, polyfit, polyvar, plot Write a script m.file to solve the questions and include it in the project report.

The Correct Answer and Explanation is:

To solve the polynomial curve fitting problem using MATLAB for the given data, you will use the least squares fitting method via the polyfit function. You will fit polynomials of order 2, 3, and 10, and then plot the results together with the original data.


MATLAB Script (save as polyfit_curve.m)

matlabCopyEdit% Polynomial Curve Fitting

% Experimental data
x = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
y = [-0.45 1.98 3.28 6.16 7.08 7.34 7.66 9.56 9.48 9.30 11.20];

% Polynomial fitting
p2 = polyfit(x, y, 2);   % 2nd order
p3 = polyfit(x, y, 3);   % 3rd order
p10 = polyfit(x, y, 10); % 10th order

% Generate fine x values for smooth curve plotting
x_fit = linspace(min(x), max(x), 500);
y2 = polyval(p2, x_fit);
y3 = polyval(p3, x_fit);
y10 = polyval(p10, x_fit);

% Plotting
figure;
plot(x, y, 'ko', 'MarkerFaceColor', 'k'); hold on;
plot(x_fit, y2, 'b-', 'LineWidth', 1.5);
plot(x_fit, y3, 'r--', 'LineWidth', 1.5);
plot(x_fit, y10, 'g:', 'LineWidth', 1.5);
legend('Experimental Data', '2nd Order', '3rd Order', '10th Order', 'Location', 'northwest');
xlabel('x');
ylabel('y');
title('Polynomial Curve Fitting');
grid on;

Explanation

Polynomial curve fitting is a mathematical process used to approximate data points with a polynomial function. In this task, we are provided with a set of 11 experimental points represented by the vectors x and y. The goal is to find polynomial equations of different degrees (2, 3, and 10) that best fit the given data.

The MATLAB function polyfit(x, y, n) is used to compute the coefficients of the polynomial of degree n that minimizes the square of the errors between the predicted and actual data values. Once the coefficients are determined, polyval(p, x) is used to evaluate the polynomial at given x values, allowing for a smooth curve to be generated and plotted.

The 2nd and 3rd order polynomials typically provide good approximations for general trends in data without overfitting. However, a 10th order polynomial can exactly fit all 11 data points because it has enough degrees of freedom. While this might seem ideal, it usually results in overfitting where the polynomial captures noise and oscillates unnecessarily between points.

When plotted together, the differences between these polynomial models become visually apparent. The 2nd and 3rd order fits give smooth curves that follow the overall shape of the data, while the 10th order polynomial may show exaggerated curvature near data extremes. This demonstrates the trade-off between underfitting and overfitting in model selection.

Scroll to Top