x = linspace(0,4*pi,100);
y = sin(x)+0.75*randn(size(x));

mystrg = '(2*pi*h^2)^(-1/2)*exp(-0.5*((x-mu)/h).^2)';
wfun = inline(mystrg);


yhatnw = zeros(size(x)); %% for estimated values
yhatlin = zeros(size(x));
n = length(x); %% all the evaluation points
h = 1; %% Scale

for i = 1:n % points
 w = wfun(h,x(i),x);
 yhatnw(i) = sum(w.*y)/sum(w);
end

plot(x,[yhatnw' y'],'.');

pause

%%
for i = 1:n
    w = wfun(h,x(i),x);
    xc = x - x(i);
    s2 = sum(xc.^2.*w)/n;
    s1 = sum(xc.*w)/n;
    s0 = sum(w)/n;
    yhatlin(i) = sum(((s2-s1*xc).*w.*y)/(s2*s0-s1^2))/n;
end

    plot(x,[yhatnw' y' yhatlin'],'.');
