%
% Un segundo ejemplo de fiteo.
%
close all;
figure;
axes('FontSize', 14);

clear xdata ydata;
xdata = 0:0.05:pi;
ydata = sin(xdata);
wdata = 0 * xdata + 1;

ndata = length(xdata);
%
plot(xdata, ydata, 'LineWidth', 2, 'Color', 'b');
xlim([0 pi/2]);
ylim([0 1.30]);
%hold on;
%fplot('sin(x)', [-pi 2*pi], '--b');


GradoDelPolinomio = 8;

clear coefs;
coefs = ajustarpol(GradoDelPolinomio, wdata, xdata, ydata);

n1 = GradoDelPolinomio + 1;
n2 = GradoDelPolinomio + 2;
clear icoefs;
for i = 1:n1
  icoefs(n2 - i) = coefs(i);
end

fpol = @(x) polyval(icoefs, x);

x2 = -pi:0.05:2*pi;
y2 = fpol(x2);

hold on;
plot(x2, y2, 'r');
fplot(fpol, [-pi 2*pi], 'r');

