Mercurial > hg > octave-nkf
annotate scripts/special-matrix/sylvester_matrix.m @ 11032:c9b0a75b02e8
Make all regexp in Octave compatible with both POSIX and PCRE.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 28 Sep 2010 09:25:14 -0700 |
parents | f0c3d3fc4903 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2004, 2005, 2006, |
8920 | 2 ## 2007, 2008, 2009 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 ## @tex | |
24 ## $n = 2^k$. | |
25 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
26 ## @ifnottex |
3369 | 27 ## n = 2^k. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
28 ## @end ifnottex |
5642 | 29 ## @seealso{hankel, vander, hilb, invhilb, toeplitz} |
3369 | 30 ## @end deftypefn |
3140 | 31 |
32 ## Author: jwe | |
33 | |
34 function retval = sylvester_matrix (k) | |
35 | |
36 if (nargin != 1) | |
6046 | 37 print_usage (); |
3140 | 38 endif |
39 | |
4030 | 40 if (isscalar (k)) |
3140 | 41 if (k < 1) |
42 retval = 1; | |
43 else | |
44 tmp = sylvester_matrix (k-1); | |
45 retval = [tmp, tmp; tmp, -tmp]; | |
46 endif | |
47 else | |
48 error ("sylvester_matrix: expecting scalar argument"); | |
49 endif | |
50 | |
51 endfunction | |
7411 | 52 |
53 %!assert((sylvester_matrix (1) == [1, 1; 1, -1] | |
54 %! && (sylvester_matrix (2) | |
55 %! == [1, 1, 1, 1; 1, -1, 1, -1; 1, 1, -1, -1; 1, -1, -1, 1]))); | |
56 | |
57 %!error sylvester_matrix ([1, 2; 3, 4]); | |
58 | |
59 %!error sylvester_matrix (); | |
60 | |
61 %!error sylvester_matrix (1, 2); | |
62 |