Mercurial > hg > octave-nkf
annotate scripts/linear-algebra/commutation_matrix.m @ 10687:a8ce6bdecce5
Improve documentation strings.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 08 Jun 2010 20:22:38 -0700 |
parents | f0c3d3fc4903 |
children | 3140cb7a05a1 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1995, 1996, 1999, 2000, 2002, 2005, 2006, 2007, 2009 |
7017 | 2 ## Kurt Hornik |
3426 | 3 ## |
3922 | 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. | |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
2540 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 14 ## General Public License for more details. |
15 ## | |
2540 | 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/>. | |
2540 | 19 |
3321 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} commutation_matrix (@var{m}, @var{n}) | |
22 ## Return the commutation matrix | |
23 ## @tex | |
24 ## $K_{m,n}$ | |
25 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
26 ## @ifnottex |
3321 | 27 ## K(m,n) |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
28 ## @end ifnottex |
3321 | 29 ## which is the unique |
30 ## @tex | |
31 ## $m n \times m n$ | |
32 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
33 ## @ifnottex |
3321 | 34 ## @var{m}*@var{n} by @var{m}*@var{n} |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
35 ## @end ifnottex |
3321 | 36 ## matrix such that |
37 ## @tex | |
38 ## $K_{m,n} \cdot {\rm vec} (A) = {\rm vec} (A^T)$ | |
39 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
40 ## @ifnottex |
3499 | 41 ## @math{K(m,n) * vec(A) = vec(A')} |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
42 ## @end ifnottex |
3321 | 43 ## for all |
44 ## @tex | |
45 ## $m\times n$ | |
46 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
47 ## @ifnottex |
3499 | 48 ## @math{m} by @math{n} |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
49 ## @end ifnottex |
3321 | 50 ## matrices |
51 ## @tex | |
52 ## $A$. | |
53 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
54 ## @ifnottex |
3499 | 55 ## @math{A}. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
56 ## @end ifnottex |
3426 | 57 ## |
3321 | 58 ## If only one argument @var{m} is given, |
59 ## @tex | |
60 ## $K_{m,m}$ | |
61 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
62 ## @ifnottex |
3499 | 63 ## @math{K(m,m)} |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
64 ## @end ifnottex |
3321 | 65 ## is returned. |
3426 | 66 ## |
2540 | 67 ## See Magnus and Neudecker (1988), Matrix differential calculus with |
68 ## applications in statistics and econometrics. | |
3321 | 69 ## @end deftypefn |
2540 | 70 |
5428 | 71 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2540 | 72 ## Created: 8 May 1995 |
73 ## Adapted-By: jwe | |
74 | |
75 function k = commutation_matrix (m, n) | |
3426 | 76 |
2540 | 77 if (nargin < 1 || nargin > 2) |
6046 | 78 print_usage (); |
2540 | 79 else |
4030 | 80 if (! (isscalar (m) && m == round (m) && m > 0)) |
2540 | 81 error ("commutation_matrix: m must be a positive integer"); |
82 endif | |
83 if (nargin == 1) | |
84 n = m; | |
4030 | 85 elseif (! (isscalar (n) && n == round (n) && n > 0)) |
2540 | 86 error ("commutation_matrix: n must be a positive integer"); |
87 endif | |
88 endif | |
3426 | 89 |
2540 | 90 ## It is clearly possible to make this a LOT faster! |
91 k = zeros (m * n, m * n); | |
92 for i = 1 : m | |
93 for j = 1 : n | |
94 k ((i - 1) * n + j, (j - 1) * m + i) = 1; | |
95 endfor | |
96 endfor | |
97 | |
98 endfunction |