home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / SPECMAT.DI$ / INVHILB.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  603 b   |  24 lines

  1. function H = invhilb(n) 
  2. %INVHILB Inverse Hilbert matrix.
  3. %    INVHILB(N) is the inverse of the N by N matrix with elements
  4. %    1/(i+j-1), which is a famous example of a badly conditioned
  5. %    matrix.  The result is exact for  N  less than about 15.
  6. %
  7. %    See also HILB.
  8.  
  9. %    C. Moler, 4-30-87.
  10. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  11.  
  12. p = n;
  13. H = zeros(n);
  14. for i = 1:n
  15.     if i > 1, p = ((n-i+1)*p*(n+i-1))/(i-1)^2; end
  16.     r = p*p;
  17.     H(i,i) = r/(2*i-1);
  18.     for j = i+1:n
  19.         r = -((n-j+1)*r*(n+j-1))/(j-1)^2;
  20.         H(i,j) = r/(i+j-1);
  21.         H(j,i) = r/(i+j-1);
  22.     end
  23. end
  24.