clear;

x = [ 1 2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19  20]';

y = [ 2.6888   -0.4724    3.7286    5.6471    1.1164    4.3160    5.2080  -0.3875    0.0181    4.1423    2.3002    4.5800    4.9312    4.8238    6.0805    4.9372    6.0817    1.3951    3.8604    3.6866]';

n = length(x);
plot(x,y);
title('Regresión lineal');
xlabel('x');
ylabel('y');

d = [x, ones(n, 1)];

p = inv(d'*d)*d'*y;
m = p(1)
b = p(2)
