v=@(t) [1,sin(2*pi*t/12),cos(2*pi*t/12)];
% basis functions tht we are using to find H(t), arranged in a row vector 3x1

A=[v(0); v(2);v(4); v(6);v(8);v(10)]; % building the matrix, each row is the basis functions calculated in the points we have t=(0,2,4,6,8,10)
y=[1;1.6;1.4;0.6;0.2;0.8]; % column vectors with the values that we want to approximate

% A is not square, so we make it square; A is 6x3; y is 6x1

B=A'*A; % matrix A' (A transpose) times A itself; B is 3x3 
z=A'*y; % matrix A' (A transpose) times y; z is 3x1

c=B\z % solve the system, find c, columns vector 3x1
i=0;
for t=0:2:10 % for all the times we have, calculate the function with the coefficients we have found in the points we used to approximate it; we get the residual in this way
    i=i+1; % just a counter to cycle through the components of w
    w(i)=v(t)*c % product of a 1x3 and a 3x1 vector: the result is a scalar
end

w-y % residuals
