clear; clc; close all;

rng(3);
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(N, 1)];
v = A \ y;
a = v(1);
b = v(2);
x_ = linspace(0, 1, 100);
y_ = a * x_ + b;
plot(x_, y_, "--");

A = [x.^2, x, ones(N, 1)];
v = A \ y
a = v(1);
b = v(2);
c = v(3);
y_ = a * x_.^2 + b * x_ + c;
plot(x_, y_, "--");


