Mercurial > hg > octave-nkf
annotate scripts/special-matrix/wilkinson.m @ 14026:3781981be535 ss-3-5-90
snapshot 3.5.90
* configure.ac (AC_INIT): Version is now 3.5.90.
(OCTAVE_API_VERSION_NUMBER): Now 46.
(OCTAVE_RELEASE_DATE): Now 2011-12-11.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 11 Dec 2011 23:18:31 -0500 |
parents | 3a2f28c08fbd |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1999-2011 Peter Ekberg |
5827 | 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. | |
5827 | 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/>. | |
5827 | 18 |
19 ## -*- texinfo -*- | |
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 | 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 | 27 ## @end deftypefn |
28 | |
29 ## Author: Peter Ekberg | |
30 ## (peda) | |
31 | |
32 function retval = wilkinson (n) | |
33 | |
34 if (nargin != 1) | |
35 print_usage (); | |
36 endif | |
37 | |
13890
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
38 if (! (isscalar (n) && n >= 0 && (n == fix (n)))) |
12551
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 | 40 endif |
41 | |
42 side = ones (n-1, 1); | |
43 center = abs (-(n-1)/2:(n-1)/2); | |
44 retval = diag (side, -1) + diag (center) + diag (side, 1); | |
45 | |
46 endfunction | |
11098
dcde7c5a1d29
new tests for special-matrix functions
John W. Eaton <jwe@octave.org>
parents:
10791
diff
changeset
|
47 |
13890
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
48 |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
49 %!assert (wilkinson (0), []) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
50 %!assert (wilkinson (1), 0) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
51 %!assert (wilkinson (2), [0.5,1;1,0.5]) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
52 %!assert (wilkinson (3), [1,1,0;1,0,1;0,1,1]) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
53 %!assert (wilkinson (4), [1.5,1,0,0;1,0.5,1,0;0,1,0.5,1;0,0,1,1.5]) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
54 |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
55 %% Test input validation |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
56 %!error wilkinson () |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
57 %!error wilkinson (1,2) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
58 %!error <N must be a non-negative integer> wilkinson (ones (2)) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
59 %!error <N must be a non-negative integer> wilkinson (-1) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
60 %!error <N must be a non-negative integer> wilkinson (1.5) |
3a2f28c08fbd
wilkinson.m: Use Octave spacing conventions in code. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
61 |