2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
3369
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} hilb (@var{n}) |
|
22 ## Return the Hilbert matrix of order @var{n}. The |
|
23 ## @iftex |
|
24 ## @tex |
|
25 ## $i,\,j$ |
|
26 ## @end tex |
|
27 ## @end iftex |
|
28 ## @ifinfo |
|
29 ## i, j |
|
30 ## @end ifinfo |
|
31 ## element of a Hilbert matrix is defined as |
|
32 ## @iftex |
|
33 ## @tex |
|
34 ## $$ |
|
35 ## H (i, j) = {1 \over (i + j - 1)} |
|
36 ## $$ |
|
37 ## @end tex |
|
38 ## @end iftex |
|
39 ## @ifinfo |
|
40 ## |
|
41 ## @example |
|
42 ## H (i, j) = 1 / (i + j - 1) |
|
43 ## @end example |
|
44 ## @end ifinfo |
|
45 ## @end deftypefn |
3408
|
46 ## @seealso{hankel, vander, sylvester_matrix, invhilb, and toeplitz} |
4
|
47 |
2314
|
48 ## Author: jwe |
|
49 |
2311
|
50 function retval = hilb (n) |
4
|
51 |
|
52 |
|
53 if (nargin != 1) |
904
|
54 usage ("hilb (n)"); |
4
|
55 endif |
|
56 |
|
57 nmax = length (n); |
|
58 if (nmax == 1) |
|
59 retval = zeros (n); |
556
|
60 tmp = 1:n; |
|
61 for i = 1:n |
|
62 retval (i, :) = 1.0 ./ (tmp + (i - 1)); |
4
|
63 endfor |
|
64 else |
|
65 error ("hilb: expecting scalar argument, found something else"); |
|
66 endif |
|
67 |
|
68 endfunction |