function [a] = least_squares(x,y,m)
% This function computes an approximant 
% of the data [x,y] (x nodes, y measurements)
% by using polynomial basis functions 
%
% psi_0(x)=1,   psi_1(x)=x, ...,   psi_m(x)=x^m
%
% and a least squares estimate. 
%
% Input x -> column vector of nodes (not necessarily distinct)
%       y -> column vector of measurements at x 

%       a -> coefficients of the polynomial approximant

n=length(x);
B=zeros(n,m+1);

for ii=1:m+1
    B(:,ii) = x.^(ii-1);
end

a=BS(B'*B,B'*y);


end

