Mercurial > hg > octave-nkf
annotate scripts/special-matrix/hilb.m @ 11523:fd0a3ac60b0e
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 14 Jan 2011 05:47:45 -0500 |
parents | 693e22af08ae |
children | 4d777e05d47c |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1993-2011 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
245 | 18 |
3369 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} hilb (@var{n}) | |
21 ## Return the Hilbert matrix of order @var{n}. The | |
22 ## @tex | |
23 ## $i,\,j$ | |
24 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
25 ## @ifnottex |
3369 | 26 ## i, j |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
27 ## @end ifnottex |
3369 | 28 ## element of a Hilbert matrix is defined as |
29 ## @tex | |
30 ## $$ | |
31 ## H (i, j) = {1 \over (i + j - 1)} | |
32 ## $$ | |
33 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
34 ## @ifnottex |
3426 | 35 ## |
3369 | 36 ## @example |
37 ## H (i, j) = 1 / (i + j - 1) | |
38 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
39 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
40 ## @end ifnottex |
5642 | 41 ## @seealso{hankel, vander, sylvester_matrix, invhilb, toeplitz} |
3369 | 42 ## @end deftypefn |
4 | 43 |
2314 | 44 ## Author: jwe |
45 | |
2311 | 46 function retval = hilb (n) |
4 | 47 |
48 | |
49 if (nargin != 1) | |
6046 | 50 print_usage (); |
4 | 51 endif |
52 | |
53 nmax = length (n); | |
54 if (nmax == 1) | |
55 retval = zeros (n); | |
556 | 56 tmp = 1:n; |
57 for i = 1:n | |
58 retval (i, :) = 1.0 ./ (tmp + (i - 1)); | |
4 | 59 endfor |
60 else | |
61 error ("hilb: expecting scalar argument, found something else"); | |
62 endif | |
63 | |
64 endfunction | |
7411 | 65 |
66 %!assert((hilb (2) == [1, 1/2; 1/2, 1/3] | |
67 %! && hilb (3) == [1, 1/2, 1/3; 1/2, 1/3, 1/4; 1/3, 1/4, 1/5])); | |
68 | |
69 %!error hilb (); | |
70 | |
71 %!error hilb (1, 2); | |
72 |