7017
|
1 ## Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2004, 2005, 2006, |
|
2 ## 2007 John W. Eaton |
3140
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3140
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
3140
|
19 |
3369
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} sylvester_matrix (@var{k}) |
|
22 ## Return the Sylvester matrix of order |
|
23 ## @iftex |
|
24 ## @tex |
|
25 ## $n = 2^k$. |
|
26 ## @end tex |
|
27 ## @end iftex |
|
28 ## @ifinfo |
|
29 ## n = 2^k. |
|
30 ## @end ifinfo |
5642
|
31 ## @seealso{hankel, vander, hilb, invhilb, toeplitz} |
3369
|
32 ## @end deftypefn |
3140
|
33 |
|
34 ## Author: jwe |
|
35 |
|
36 function retval = sylvester_matrix (k) |
|
37 |
|
38 if (nargin != 1) |
6046
|
39 print_usage (); |
3140
|
40 endif |
|
41 |
4030
|
42 if (isscalar (k)) |
3140
|
43 if (k < 1) |
|
44 retval = 1; |
|
45 else |
|
46 tmp = sylvester_matrix (k-1); |
|
47 retval = [tmp, tmp; tmp, -tmp]; |
|
48 endif |
|
49 else |
|
50 error ("sylvester_matrix: expecting scalar argument"); |
|
51 endif |
|
52 |
|
53 endfunction |
7411
|
54 |
|
55 %!assert((sylvester_matrix (1) == [1, 1; 1, -1] |
|
56 %! && (sylvester_matrix (2) |
|
57 %! == [1, 1, 1, 1; 1, -1, 1, -1; 1, 1, -1, -1; 1, -1, -1, 1]))); |
|
58 |
|
59 %!error sylvester_matrix ([1, 2; 3, 4]); |
|
60 |
|
61 %!error sylvester_matrix (); |
|
62 |
|
63 %!error sylvester_matrix (1, 2); |
|
64 |