function [a,b,c,sx] = ajusta_parabola(x,gx,xp,fxp,pasta,rotulo)
%x, g sao as amostras e xp, fp eh a funcao original sem erros
%quadrados minimos
n = size(x,2);
A = zeros(n,1);
for i = 1:n
    A(i,1) = 1;
    A(i,2) = x(i);
    A(i,3) = x(i)^2;
end

M = A'*A;
bv = A'*gx';
alpha = M\bv;

a = alpha(3);
b = alpha(2);
c = alpha(1);
sx = A*alpha;

np = length(xp);

for i = 1:np
    sxp(i) = a*xp(i)^2 + b*xp(i) + c;
end
set(gca,'Fontsize', 20)
set(gca,'LineWidth',50) 
plot(xp,sxp,'r')
hold on
plot(xp,fxp,'--m')

plot(x,gx,'*')
plot(x,gx,'o')
%title(rotulo);
axis([-1.5 1.5 -.5 3.5])
saveas(gcf,sprintf('%s/%s.eps',pasta,rotulo),'epsc');



