2313
|
1 ## Copyright (C) 1996 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
245
|
19 |
2311
|
20 ## usage: invhilb (n) |
|
21 ## |
|
22 ## Return the inverse of a Hilbert matrix of order n. This is slow but |
|
23 ## exact. Compare with inv (hilb (n)). |
|
24 ## |
|
25 ## See also: hankel, vander, hadamard, hilb, toeplitz |
4
|
26 |
2311
|
27 function retval = invhilb (n) |
4
|
28 |
|
29 if (nargin != 1) |
904
|
30 usage ("invhilb (n)"); |
4
|
31 endif |
|
32 |
|
33 nmax = length (n); |
|
34 if (nmax == 1) |
|
35 retval = zeros (n); |
|
36 for l = 1:n |
|
37 for k = l:n |
|
38 tmp = 1; |
|
39 for i = 1:n |
|
40 tmp = tmp * (i + k - 1); |
|
41 endfor |
|
42 for i = 1:n |
|
43 if (i != k) |
|
44 tmp = tmp * (l + i - 1); |
|
45 endif |
|
46 endfor |
|
47 for i = 1:n |
|
48 if (i != l) |
|
49 tmp = tmp / (i - l); |
|
50 endif |
|
51 endfor |
|
52 for i = 1:n |
|
53 if (i != k) |
|
54 tmp = tmp / (i - k); |
|
55 endif |
|
56 endfor |
|
57 retval (k, l) = tmp; |
|
58 retval (l, k) = tmp; |
|
59 endfor |
|
60 endfor |
|
61 else |
|
62 error ("hilb: expecting scalar argument, found something else"); |
|
63 endif |
|
64 |
|
65 endfunction |