245
|
1 # Copyright (C) 1993 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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
4
|
19 function retval = invhilb (n) |
|
20 |
|
21 # usage: invhilb (n) |
|
22 # |
|
23 # Return the inverse of a Hilbert matrix of order n. This is slow but |
|
24 # exact. Compare with inv (hilb (n)). |
|
25 # |
|
26 # See also: hankel, vander, hadamard, hilb, toeplitz |
|
27 |
|
28 if (nargin != 1) |
|
29 error ("usage: invhilb (n)"); |
|
30 endif |
|
31 |
|
32 nmax = length (n); |
|
33 if (nmax == 1) |
|
34 retval = zeros (n); |
|
35 for l = 1:n |
|
36 for k = l:n |
|
37 tmp = 1; |
|
38 for i = 1:n |
|
39 tmp = tmp * (i + k - 1); |
|
40 endfor |
|
41 for i = 1:n |
|
42 if (i != k) |
|
43 tmp = tmp * (l + i - 1); |
|
44 endif |
|
45 endfor |
|
46 for i = 1:n |
|
47 if (i != l) |
|
48 tmp = tmp / (i - l); |
|
49 endif |
|
50 endfor |
|
51 for i = 1:n |
|
52 if (i != k) |
|
53 tmp = tmp / (i - k); |
|
54 endif |
|
55 endfor |
|
56 retval (k, l) = tmp; |
|
57 retval (l, k) = tmp; |
|
58 endfor |
|
59 endfor |
|
60 else |
|
61 error ("hilb: expecting scalar argument, found something else"); |
|
62 endif |
|
63 |
|
64 endfunction |