function test_least_squares(N,m)
%
% This function tests the least square algorithm
% coded in least_squares.m
%
% Input  N -> number of points in the dataset (synthetic data)
%        m -> polynomial order of the approximant

% Here we generate the synthetic data set
x=randn(N,1);
x=2*x;
y=exp(sin(2*x))+2*rand(N,1);

% Here we compute the coefficients of the polynomial approximant
[a] = least_squares(x,y,m);

X=linspace(min(x),max(x),300);
Y=zeros(size(X));

for ii=1:m+1
    Y =Y + a(ii).*X.^(ii-1);
end

figure(1)
clf
plot(x,y,'r.') % data
hold
plot(X,Y)      % least squares polynomial
xlabel('x','Fontsize',20)
set(gca,'Fontsize',20)
box on


% Here we show that least squares can yield 
% a polynomial interpolant 
% (to this end set m=6)

x=linspace(0,2*pi,5)';
y=sin(x);

[a] = least_squares(x,y,m);

X=linspace(min(x),max(x),300);
Y=zeros(size(X));

for ii=1:m+1
    Y =Y + a(ii).*X.^(ii-1);
end

figure(2)
clf
plot(x,y,'r.') % plot of data set
hold
plot(X,Y) % least squares polynomial
xlabel('x','Fontsize',20)
set(gca,'Fontsize',20)
box on





end

