% Inverse of Hilbert matrix
% Author: Dirk Laurie

function retval = invhilb (n)

  if (nargin != 1)
    usage ("invhilb (n)");
  endif

  nmax = length (n);
  if (nmax == 1)
    retval = zeros (n); 
    k=1:n; p=k.*bincoeff(k+n-1,k-1).*bincoeff(n,k);
    p(2:2:n)=-p(2:2:n);
    if n<203,
      for l = 1:n
        retval(l,:)=(p(l)*p)./(l:l+n-1); 
      endfor
    else
      for l = 1:n
        retval(l,:)=p(l)*(p./(l:l+n-1));
      endfor
    endif
  else
    error ("invhilb: expecting scalar argument, found something else");
  endif

endfunction
