

x=[0:0.1:2*pi];
n = length(x);
y = sin(x) + 0.3*randn(1,n);

% approssimazione ai minimi quadrati:
for q=[0 1 2 3 4 5]
  figure(10); plot(x,y,'ro'); hold,  
             c=polyfit(x,y,q); errsq=sum((y-polyval(c,x)).^2);
			 disp(['gradopol=' num2str(q) '   sqm=' num2str(errsq)]);
             plot(x,polyval(c,x),'b-'); 
             hold,
             title(['grado del polinomio =' num2str(q)]), pause;
end;



