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');

A = [x, ones(size(x))];
v = A \ y
x_range = linspace(0, 1, 100);
y_range = v(1) * x_range + v(2);
plot(x_range, y_range, "--");

A = [x .^ 2, x, ones(size(x))];
v = A \ y
x_range = linspace(0, 1, 100);
y_range = polyval(v, x_range);
plot(x_range, y_range, "--");