Mercurial > hg > octave-lyh
annotate scripts/special-matrix/hilb.m @ 15806:01d4f742d75d
doc: Re-organize and improve Java Interface documentation.
* doc/interpreter/java.txi: Add usejava, isjava functions, debug_java,
java_matrix_autoconversion, java_unsigned_autoconversion to docs.
Re-organize to put functions in logical order. Add new "Dialog Box Functions"
node.
* doc/interpreter/system.txi: Remove usejava from list of system functions.
* libinterp/octave-value/ov-java.cc(FjavaObject, FjavaMethod,
Fjava_unsigned_autoconversion): Improve docstrings.
* scripts/java/javaArray.m: Tweak docstring.
* scripts/java/listdlg.m: Wrap long lines in docstring. Improve
code example in docstring.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 17 Dec 2012 10:23:43 -0800 |
parents | f3d52523cde1 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13872
diff
changeset
|
1 ## Copyright (C) 1993-2012 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}) | |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
21 ## Return the Hilbert matrix of order @var{n}. The @math{i,j} element |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
22 ## of a Hilbert matrix is defined as |
3369 | 23 ## @tex |
24 ## $$ | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
25 ## H(i, j) = {1 \over (i + j - 1)} |
3369 | 26 ## $$ |
27 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
28 ## @ifnottex |
3426 | 29 ## |
3369 | 30 ## @example |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
31 ## H(i, j) = 1 / (i + j - 1) |
3369 | 32 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
9211
diff
changeset
|
33 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
34 ## @end ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
35 ## |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
36 ## Hilbert matrices are close to being singular which make them difficult to |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
37 ## invert with numerical routines. |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
38 ## Comparing the condition number of a random matrix 5x5 matrix with that of |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
39 ## a Hilbert matrix of order 5 reveals just how difficult the problem is. |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
40 ## |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
41 ## @example |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
42 ## @group |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
43 ## cond (rand (5)) |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
44 ## @result{} 14.392 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
45 ## cond (hilb (5)) |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
46 ## @result{} 4.7661e+05 |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
47 ## @end group |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
48 ## @end example |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
49 ## |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
50 ## @seealso{invhilb} |
3369 | 51 ## @end deftypefn |
4 | 52 |
2314 | 53 ## Author: jwe |
54 | |
2311 | 55 function retval = hilb (n) |
4 | 56 |
57 if (nargin != 1) | |
6046 | 58 print_usage (); |
13872
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
59 elseif (! isscalar (n)) |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
60 error ("hilb: N must be a scalar integer"); |
4 | 61 endif |
62 | |
13872
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
63 retval = zeros (n); |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
64 tmp = 1:n; |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
65 for i = 1:n |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
66 retval(i, :) = 1.0 ./ tmp; |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
67 tmp++; |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
68 endfor |
4 | 69 |
70 endfunction | |
7411 | 71 |
13872
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
72 |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
73 %!assert (hilb (2), [1, 1/2; 1/2, 1/3]) |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
74 %!assert (hilb (3), [1, 1/2, 1/3; 1/2, 1/3, 1/4; 1/3, 1/4, 1/5]) |
7411 | 75 |
13872
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
76 %!error hilb () |
779e15b69738
hilb.m: 10% speedup by using in-place accumulation.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
77 %!error hilb (1, 2) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
78 %!error <N must be a scalar integer> hilb (ones (2)) |
7411 | 79 |