% exact formula for inverse of Hilbert matrix of order N
% implementation by Cleve Moler
function H=InverseHilbertMatrix(N)

   H = zeros(N,N);
   p = N;
   for i = 1:N
       r = p*p;
       H(i,i) = r/(2*i-1);
       for j = i+1:N
           r = -((N-j+1)*r*(N+j-1))/(j-1)^2;
           H(i,j) = r/(i+j-1);
           H(j,i) = r/(i+j-1);
       end
       p = ((N-i)*p*(N+i))/(i^2);
   end