annotate scripts/special-matrix/wilkinson.m @ 12639:4d777e05d47c stable

doc: Review and update documentation for "Matrix Manipulation" chapter. * matrix.txi, arrayfun.m, blkdiag.m, fliplr.m, flipud.m, logspace.m, postpad.m, prepad.m, randi.m, repmat.m, rot90.m, rotdim.m, shiftdim.m, sortrows.m, vech.m, xor.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, pascal.m, rosser.m, sylvester_matrix.m, toeplitz.m, vander.m, wilkinson.m, bsxfun.cc, find.cc, lookup.cc, rand.cc, tril.cc, data.cc, arrayfun.m, blkdiag.m, fliplr.m, flipud.m, logspace.m, postpad.m, prepad.m, randi.m, repmat.m, rot90.m, rotdim.m, shiftdim.m, sortrows.m, vech.m, xor.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, pascal.m, rosser.m, sylvester_matrix.m, toeplitz.m, vander.m, wilkinson.m, bsxfun.cc (bsxfun), find.cc (find), lookup.cc (lookup), rand.cc (rand, randn, rande, randg, randp), tril.cc (triu), data.cc (all, any, horzcat, vertcat, cat, permute, ipermute, ones, zeros, eye, linspace, resize, reshape, issorted, diff): Improve docstrings
author Rik <octave@nomad.inbox5.com>
date Sun, 01 May 2011 08:55:15 -0700
parents e4a1ede4e832
children 3a2f28c08fbd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11098
diff changeset
1 ## Copyright (C) 1999-2011 Peter Ekberg
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
2 ##
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
4 ##
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5827
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5827
diff changeset
8 ## your option) any later version.
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
9 ##
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
14 ##
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5827
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5827
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
18
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
20 ## @deftypefn {Function File} {} wilkinson (@var{n})
10791
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
21 ## Return the Wilkinson matrix of order @var{n}. Wilkinson matrices are
3140cb7a05a1 Add spellchecker scripts for Octave and run spellcheck of documentation
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
22 ## symmetric and tridiagonal with pairs of nearly, but not exactly, equal
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12551
diff changeset
23 ## eigenvalues. They are useful in testing the behavior and performance
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12551
diff changeset
24 ## of eigenvalue solvers.
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
25 ##
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 12551
diff changeset
26 ## @seealso{rosser, eig}
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
27 ## @end deftypefn
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
28
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
29 ## Author: Peter Ekberg
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
30 ## (peda)
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
31
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
32 function retval = wilkinson (n)
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
33
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
34 if (nargin != 1)
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
35 print_usage ();
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
36 endif
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
37
12551
e4a1ede4e832 Update test for 'wilkinson(1)' to reflect changes to diag().
John W. Eaton <jwe@octave.org>
parents: 12448
diff changeset
38 if (! (isscalar (n) && (n == fix (n)) && n >= 0))
e4a1ede4e832 Update test for 'wilkinson(1)' to reflect changes to diag().
John W. Eaton <jwe@octave.org>
parents: 12448
diff changeset
39 error ("wilkinson: N must be a non-negative integer");
5827
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
40 endif
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
41
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
42 side = ones (n-1, 1);
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
43 center = abs (-(n-1)/2:(n-1)/2);
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
44 retval = diag (side, -1) + diag (center) + diag (side, 1);
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
45
1fe78adb91bc [project @ 2006-05-22 06:25:14 by jwe]
jwe
parents:
diff changeset
46 endfunction
11098
dcde7c5a1d29 new tests for special-matrix functions
John W. Eaton <jwe@octave.org>
parents: 10791
diff changeset
47
12551
e4a1ede4e832 Update test for 'wilkinson(1)' to reflect changes to diag().
John W. Eaton <jwe@octave.org>
parents: 12448
diff changeset
48 %!assert (wilkinson(0), [])
e4a1ede4e832 Update test for 'wilkinson(1)' to reflect changes to diag().
John W. Eaton <jwe@octave.org>
parents: 12448
diff changeset
49 %!assert (wilkinson(1), 0)
11098
dcde7c5a1d29 new tests for special-matrix functions
John W. Eaton <jwe@octave.org>
parents: 10791
diff changeset
50 %!assert (wilkinson(2), [0.5,1;1,0.5])
dcde7c5a1d29 new tests for special-matrix functions
John W. Eaton <jwe@octave.org>
parents: 10791
diff changeset
51 %!assert (wilkinson(3), [1,1,0;1,0,1;0,1,1])
dcde7c5a1d29 new tests for special-matrix functions
John W. Eaton <jwe@octave.org>
parents: 10791
diff changeset
52 %!assert (wilkinson(4), [1.5,1,0,0;1,0.5,1,0;0,1,0.5,1;0,0,1,1.5])
dcde7c5a1d29 new tests for special-matrix functions
John W. Eaton <jwe@octave.org>
parents: 10791
diff changeset
53 %!error (wilkinson())
12448
f2c080bbd8a5 Fix documentation bugs uncovered while rewriting munge-texi.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
54 %!error (wilkinson(1,2))