% Example of polyfit
% Minas Spetsakis, Nov. 2024

N = 20;
deg = 12;
X = linspace(-1, 1, N)';
Y = randn(1,N-2)';
Y=conv(Y,[.5,1,.5]);

p = mypolyfit(X, Y, deg);
p1 = mypolyfit1(X, Y, deg);

fplot(@(x)polyval(p, x), [-1.01,1.01],'r');
hold on
fplot(@(x)polyval(p1,x), [-1.01,1.01],'b');
plot(X,Y,'ob');
hold off
norm(p-p1)
fprintf("Fit for mypolyfit:  %7.2e\n", norm(Y-polyval(p, X)));
fprintf("Fit for mypolyfit1: %7.2e\n", norm(Y-polyval(p1,X)));

