Mercurial > hg > octave-lyh
annotate scripts/deprecated/sylvester_matrix.m @ 17478:b8ecdb6ce2f8
assert.m: Speed up function by ~16% by not pre-calculating warning message.
* scripts/testfun/assert.m: Don't pre-calculate "in" warning message since it
is only used a small fraction of the time when there is an actual error.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 23 Sep 2013 13:43:23 -0700 |
parents | 1c89599167a6 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12644
diff
changeset
|
1 ## Copyright (C) 1996-2012 John W. Eaton |
3140 | 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. | |
3140 | 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/>. | |
3140 | 18 |
3369 | 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 | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
25 ## @ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
26 ## n = 2^@var{k}. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7411
diff
changeset
|
27 ## @end ifnottex |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
28 ## |
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
29 ## @seealso{toeplitz, hankel} |
3369 | 30 ## @end deftypefn |
3140 | 31 |
32 ## Author: jwe | |
33 | |
34 function retval = sylvester_matrix (k) | |
35 | |
12644
e205ebe2ba67
Deprecate sylvester_matrix.m function
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
36 persistent warned = false; |
e205ebe2ba67
Deprecate sylvester_matrix.m function
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
37 if (! warned) |
e205ebe2ba67
Deprecate sylvester_matrix.m function
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
38 warned = true; |
e205ebe2ba67
Deprecate sylvester_matrix.m function
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
39 warning ("Octave:deprecated-function", |
e205ebe2ba67
Deprecate sylvester_matrix.m function
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
40 "sylvester_matrix is obsolete and will be removed from a future version of Octave; please use hadamard(2^k) instead"); |
e205ebe2ba67
Deprecate sylvester_matrix.m function
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
41 endif |
e205ebe2ba67
Deprecate sylvester_matrix.m function
Rik <octave@nomad.inbox5.com>
parents:
12639
diff
changeset
|
42 |
3140 | 43 if (nargin != 1) |
6046 | 44 print_usage (); |
3140 | 45 endif |
46 | |
4030 | 47 if (isscalar (k)) |
3140 | 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 | |
7411 | 59 |
17346
1c89599167a6
maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents:
14138
diff
changeset
|
60 |
7411 | 61 %!assert((sylvester_matrix (1) == [1, 1; 1, -1] |
62 %! && (sylvester_matrix (2) | |
63 %! == [1, 1, 1, 1; 1, -1, 1, -1; 1, 1, -1, -1; 1, -1, -1, 1]))); | |
64 | |
65 %!error sylvester_matrix ([1, 2; 3, 4]); | |
66 | |
67 %!error sylvester_matrix (); | |
68 | |
69 %!error sylvester_matrix (1, 2); | |
70 |