% Least sqaures polynomial fitting % Calculate a polynomial fit % enter x and y data x = [1 2 3 4 5 6 7 8 9]'; y = [.9 2.4 2.8 2.1 2.7 3.6 4.2 4.4 5.1]'; X = [ones(size(x)) x x.^2 x.^3 x.^4 x.^5]; % the ones are used for the % constant (a0) term a = X\y; % solve using the Matlab backslash operator % plot the data and polynomial T = [0:0.1:10]'; Y = [ones(size(T)) T T.^2 T.^3 T.^4 T.^5 ]*a; plot(T,Y,'-',x,y,'or') title('2nd degree polynomial least squares fit ') xlabel('x') ylabel('y') pause % % % now perform the same calculations with polyfit % % standardi