function [w]=weights(d,x)
%-----------------------------------------------------------------
% This function computes the F-H's weights.
% 
% INPUTS:
% d - polinomyal degree of F-H's interpolant
% x - vector of nodes
% 
% OUTPUTS:
% w - vector of F-H's weights
% 
%-----------------------------------------------------------------
% Authors: 
%      Stefano De Marchi and Cinzia Bandiziol
%      Department of Pure and Applied Math.
%      University of Padova
%           
% Version: May 2015		
%  ----------------------------------------------------------------		% 

n=length(x);

% Compute matrix Z
Z=zeros(n,n-d);
vect_diagonals=ones(n-d,1);
t=[2:2:n-d];
vect_diagonals(t)=-1;
index_diagonals=[-d:0];
mat_diagonals=repmat(vect_diagonals,1,size(index_diagonals,2));
Z=spdiags(mat_diagonals,index_diagonals,Z);

A2=repmat(x',n,1);% nxn matrix

% Get distances between nodes and interpolat
P1=A2-A2';

% Find all of the elements where the interpolation point is on a node
[a,b]=find(P1==0);
if(size(a,1)>n)
fprintf('<< Wrong input: points in x must be distinct >>\n');
      yi(i) = NaN;
return;
end

% Compute matrix G
G=ones(n-d,n);
P2=eye(n);
P=P1+P2;
Q=ones(n,n)./P;
for k=1:n-d
    G(k,:)=prod(Q(k:k+d,:),1);
end
	
% Compute mathix of weights
w=sum(Z'.*G,1)';