7017
|
1 ## Copyright (C) 1999, 2006, 2007 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}) |
|
21 ## |
|
22 ## Return the Wilkinson matrix of order @var{n}. |
|
23 ## |
|
24 ## @seealso{hankel, vander, sylvester_matrix, hilb, invhilb, toeplitz |
|
25 ## hadamard, rosser, compan, pascal} |
|
26 ## @end deftypefn |
|
27 |
|
28 ## Author: Peter Ekberg |
|
29 ## (peda) |
|
30 |
|
31 function retval = wilkinson (n) |
|
32 |
|
33 if (nargin != 1) |
|
34 print_usage (); |
|
35 endif |
|
36 |
|
37 nmax = length (n); |
|
38 if (! (nmax == 1)) |
|
39 error ("wilkinson: expecting scalar argument, found something else"); |
|
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 |