Mercurial > hg > octave-nkf
annotate scripts/linear-algebra/duplication_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 |
3426 | 20 ## -*- texinfo -*- |
3321 | 21 ## @deftypefn {Function File} {} duplication_matrix (@var{n}) |
22 ## Return the duplication matrix | |
23 ## @iftex | |
24 ## @tex | |
25 ## $D_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 |
3499 | 29 ## @math{Dn} |
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 ## $n^2 \times n(n+1)/2$ | |
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 |
3499 | 38 ## @math{n^2} by @math{n*(n+1)/2} |
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 ## $D_n * {\rm vech} (A) = {\rm vec} (A)$ | |
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{Dn vech (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 symmetric |
50 ## @iftex | |
51 ## @tex | |
52 ## $n \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{n} 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 ## |
2540 | 68 ## See Magnus and Neudecker (1988), Matrix differential calculus with |
69 ## applications in statistics and econometrics. | |
3321 | 70 ## @end deftypefn |
2540 | 71 |
5428 | 72 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2540 | 73 ## Created: 8 May 1995 |
74 ## Adapged-By: jwe | |
75 | |
76 function d = duplication_matrix (n) | |
77 | |
78 if (nargin != 1) | |
6046 | 79 print_usage (); |
2540 | 80 endif |
81 | |
4030 | 82 if (! (isscalar (n) && n == round (n) && n > 0)) |
2540 | 83 error ("duplication_matrix: n must be a positive integer"); |
84 endif | |
85 | |
86 d = zeros (n * n, n * (n + 1) / 2); | |
87 | |
88 ## It is clearly possible to make this a LOT faster! | |
89 count = 0; | |
90 for j = 1 : n | |
91 d ((j - 1) * n + j, count + j) = 1; | |
92 for i = (j + 1) : n | |
93 d ((j - 1) * n + i, count + i) = 1; | |
94 d ((i - 1) * n + j, count + i) = 1; | |
95 endfor | |
96 count = count + n - j; | |
97 endfor | |
98 | |
99 endfunction |