clear; clc; close all;

rng(3); % fix the random seed
N = 10;
x = linspace(0, 1, N); x = x(:);
y = cos(rand(size(x)) * pi / 2) + x .^ 2;
figure; hold on; grid on; plot(x, y, 'o');

xq = linspace(0 - 0.01, 1 + 0.01, 100);
for i = 1 : 2 : 9
    coeff = polyfit(x, y, i);
    yq = polyval(coeff, xq);
    plot(xq, yq, '--');
end
