Experiment: Polynomial Fitting with Given Polynomial Function

Resource Overview

MATLAB experiment using the polynomial y=x³-6x²+5x-3 to generate dataset (xi, yi, i=1,2,...,n), adding random noise to yi using rand (uniform distribution) or randn (normal distribution), then performing 3rd-degree polynomial fitting comparison with original coefficients. Includes analysis of 2nd and 4th-degree polynomial fitting results.

Detailed Documentation

In this MATLAB experiment, we utilize the given polynomial function y = x³ - 6x² + 5x - 3 to generate a dataset consisting of points (xi, yi) where i = 1, 2, ..., n. To simulate real-world data variability, we introduce random noise to the yi values. This noise can be implemented using MATLAB's rand function (generating uniformly distributed random numbers between 0 and 1) or randn function (producing normally distributed random numbers with N(0,1) distribution). The core implementation involves using MATLAB's polyfit function for polynomial regression. We first create the clean dataset by evaluating the polynomial at various x-values, then add random perturbations to the y-values. The polyfit function is employed to perform cubic polynomial fitting (3rd degree) using the noisy data points, and the resulting coefficients are compared with the original polynomial coefficients [1, -6, 5, -3]. For comparative analysis, we extend the experiment to investigate lower and higher-order polynomial fittings. Specifically, we apply 2nd-degree (quadratic) and 4th-degree polynomial fittings to examine how the fitting accuracy and coefficient recovery vary with different polynomial orders. This comparative approach demonstrates the trade-offs between model complexity and fitting precision, highlighting potential overfitting or underfitting scenarios. The implementation workflow includes: defining the polynomial coefficients, generating x-values using linspace, calculating clean y-values, adding noise with appropriate scaling, performing polyfit with specified degrees, and comparing coefficients using norm or correlation measures. The results provide insights into polynomial regression robustness against noise and the importance of selecting appropriate model orders.