Mercurial > hg > octave-nkf
annotate scripts/linear-algebra/commutation_matrix.m @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 81d6ab3ac93c |
children | f0c3d3fc4903 |
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 ## @iftex | |
24 ## @tex | |
25 ## $K_{m,n}$ | |
26 ## @end tex | |
27 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
28 ## @ifnottex |
3321 | 29 ## K(m,n) |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
30 ## @end ifnottex |
3321 | 31 ## which is the unique |
32 ## @iftex | |
33 ## @tex | |
34 ## $m n \times m n$ | |
35 ## @end tex | |
36 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
37 ## @ifnottex |
3321 | 38 ## @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
|
39 ## @end ifnottex |
3321 | 40 ## matrix such that |
41 ## @iftex | |
42 ## @tex | |
43 ## $K_{m,n} \cdot {\rm vec} (A) = {\rm vec} (A^T)$ | |
44 ## @end tex | |
45 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
46 ## @ifnottex |
3499 | 47 ## @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
|
48 ## @end ifnottex |
3321 | 49 ## for all |
50 ## @iftex | |
51 ## @tex | |
52 ## $m\times n$ | |
53 ## @end tex | |
54 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
55 ## @ifnottex |
3499 | 56 ## @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
|
57 ## @end ifnottex |
3321 | 58 ## matrices |
59 ## @iftex | |
60 ## @tex | |
61 ## $A$. | |
62 ## @end tex | |
63 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
64 ## @ifnottex |
3499 | 65 ## @math{A}. |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
66 ## @end ifnottex |
3426 | 67 ## |
3321 | 68 ## If only one argument @var{m} is given, |
69 ## @iftex | |
70 ## @tex | |
71 ## $K_{m,m}$ | |
72 ## @end tex | |
73 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
74 ## @ifnottex |
3499 | 75 ## @math{K(m,m)} |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
76 ## @end ifnottex |
3321 | 77 ## is returned. |
3426 | 78 ## |
2540 | 79 ## See Magnus and Neudecker (1988), Matrix differential calculus with |
80 ## applications in statistics and econometrics. | |
3321 | 81 ## @end deftypefn |
2540 | 82 |
5428 | 83 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2540 | 84 ## Created: 8 May 1995 |
85 ## Adapted-By: jwe | |
86 | |
87 function k = commutation_matrix (m, n) | |
3426 | 88 |
2540 | 89 if (nargin < 1 || nargin > 2) |
6046 | 90 print_usage (); |
2540 | 91 else |
4030 | 92 if (! (isscalar (m) && m == round (m) && m > 0)) |
2540 | 93 error ("commutation_matrix: m must be a positive integer"); |
94 endif | |
95 if (nargin == 1) | |
96 n = m; | |
4030 | 97 elseif (! (isscalar (n) && n == round (n) && n > 0)) |
2540 | 98 error ("commutation_matrix: n must be a positive integer"); |
99 endif | |
100 endif | |
3426 | 101 |
2540 | 102 ## It is clearly possible to make this a LOT faster! |
103 k = zeros (m * n, m * n); | |
104 for i = 1 : m | |
105 for j = 1 : n | |
106 k ((i - 1) * n + j, (j - 1) * m + i) = 1; | |
107 endfor | |
108 endfor | |
109 | |
110 endfunction |