]> Creatis software - CreaPhase.git/blob - octave_packages/m/deprecated/sylvester_matrix.m
update packages
[CreaPhase.git] / octave_packages / m / deprecated / sylvester_matrix.m
1 ## Copyright (C) 1996-2012 John W. Eaton
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} sylvester_matrix (@var{k})
21 ## Return the Sylvester matrix of order
22 ## @tex
23 ## $n = 2^k$.
24 ## @end tex
25 ## @ifnottex
26 ## n = 2^@var{k}.
27 ## @end ifnottex
28 ##
29 ## @seealso{toeplitz, hankel}
30 ## @end deftypefn
31
32 ## Author: jwe
33
34 function retval = sylvester_matrix (k)
35
36   persistent warned = false;
37   if (! warned)
38     warned = true;
39     warning ("Octave:deprecated-function",
40              "sylvester_matrix is obsolete and will be removed from a future version of Octave; please use hadamard(2^k) instead");
41   endif
42
43   if (nargin != 1)
44     print_usage ();
45   endif
46
47   if (isscalar (k))
48     if (k < 1)
49       retval = 1;
50     else
51       tmp = sylvester_matrix (k-1);
52       retval = [tmp, tmp; tmp, -tmp];
53     endif
54   else
55     error ("sylvester_matrix: expecting scalar argument");
56   endif
57
58 endfunction
59
60 %!assert((sylvester_matrix (1) == [1, 1; 1, -1]
61 %! && (sylvester_matrix (2)
62 %! == [1, 1, 1, 1; 1, -1, 1, -1; 1, 1, -1, -1; 1, -1, -1, 1])));
63
64 %!error sylvester_matrix ([1, 2; 3, 4]);
65
66 %!error sylvester_matrix ();
67
68 %!error sylvester_matrix (1, 2);
69