MATLAB curve fitting - least squares method - wrong “fit” using high degrees
Anyone here that could help me with the following problem? The following code calculates the best polynomial fit to a given data-set, that is; a polynomial of a specified degree. Unfortunately, whatever the data-set may be, usually at degree 6 or higher, MATLAB gets a totally wrong fit. Usually the fit curves totally away from the data in a sort of exponantial-looking-manner downwards. (see the example: degree = 8). x=[1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5] % experimental x-values y=[4.3 6.2 10.1 13.5 19.8 22.6 24.7 29.2] % experimental y-values degree=8; % specify the degree A = zeros(length(x)