Mercurial > hg > octave-nkf
annotate scripts/special-matrix/wilkinson.m @ 13114:7600200a54c8
Exclude /gnulib/ from Emacs' C++ mode for .h files
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Wed, 07 Sep 2011 18:48:00 -0500 |
parents | 4d777e05d47c |
children | 3a2f28c08fbd |
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 | |
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 | 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 |
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)) |