% lect 10_3: Curve fitting with polynomials % Data points to fit x = [0.9 1.5 3 4 6 8 9.5]; y = [0.9 1.5 2.5 5.1 4.5 4.9 6.3]; % Try polynomials of degree 1-6 for n = [1 2 3 4 5 6] p = polyfit(x, y, n); % x values for plotting polynomial xp = 0.9:0.1:9.5; % Evaluate the trial polynomial yp = polyval(p, xp); plot(x, y, 'o', xp, yp); axis([0, 10, 0, 9]); xlabel('x'); ylabel('y'); s = sprintf('Polynomial fit degree %i', n); text(2,8,s,'FontSize',14); fprintf('Degree %i fit\n', n) disp(p) pause end