2540
|
1 ## Copyright (C) 1995, 1996 Kurt Hornik |
3426
|
2 ## |
2540
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
3426
|
7 ## |
2540
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
11 ## General Public License for more details. |
|
12 ## |
2540
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
3426
|
17 ## -*- texinfo -*- |
3321
|
18 ## @deftypefn {Function File} {} duplication_matrix (@var{n}) |
|
19 ## Return the duplication matrix |
|
20 ## @iftex |
|
21 ## @tex |
|
22 ## $D_n$ |
|
23 ## @end tex |
|
24 ## @end iftex |
|
25 ## @ifinfo |
|
26 ## @var{D}_@var{n} |
|
27 ## @end ifinfo |
|
28 ## which is the unique |
|
29 ## @iftex |
|
30 ## @tex |
|
31 ## $n^2 \times n(n+1)/2$ |
|
32 ## @end tex |
|
33 ## @end iftex |
|
34 ## @ifinfo |
|
35 ## @var{n}^2 by @var{n}*(@var{n}+1)/2 |
|
36 ## @end ifinfo |
|
37 ## matrix such that |
|
38 ## @iftex |
|
39 ## @tex |
|
40 ## $D_n * {\rm vech} (A) = {\rm vec} (A)$ |
|
41 ## @end tex |
|
42 ## @end iftex |
|
43 ## @ifinfo |
|
44 ## @var{D}_@var{n} \cdot vech (@var{A}) = vec (@var{A}) |
|
45 ## @end ifinfo |
|
46 ## for all symmetric |
|
47 ## @iftex |
|
48 ## @tex |
|
49 ## $n \times n$ |
|
50 ## @end tex |
|
51 ## @end iftex |
|
52 ## @ifinfo |
|
53 ## @var{n} by @var{n} |
|
54 ## @end ifinfo |
|
55 ## matrices |
|
56 ## @iftex |
|
57 ## @tex |
|
58 ## $A$. |
|
59 ## @end tex |
|
60 ## @end iftex |
|
61 ## @ifinfo |
|
62 ## @var{A}. |
|
63 ## @end ifinfo |
3426
|
64 ## |
2540
|
65 ## See Magnus and Neudecker (1988), Matrix differential calculus with |
|
66 ## applications in statistics and econometrics. |
3321
|
67 ## @end deftypefn |
2540
|
68 |
|
69 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
70 ## Created: 8 May 1995 |
|
71 ## Adapged-By: jwe |
|
72 |
|
73 function d = duplication_matrix (n) |
|
74 |
|
75 if (nargin != 1) |
|
76 usage ("duplication_matrix (n)"); |
|
77 endif |
|
78 |
|
79 if (! (is_scalar (n) && n == round (n) && n > 0)) |
|
80 error ("duplication_matrix: n must be a positive integer"); |
|
81 endif |
|
82 |
|
83 d = zeros (n * n, n * (n + 1) / 2); |
|
84 |
|
85 ## It is clearly possible to make this a LOT faster! |
|
86 count = 0; |
|
87 for j = 1 : n |
|
88 d ((j - 1) * n + j, count + j) = 1; |
|
89 for i = (j + 1) : n |
|
90 d ((j - 1) * n + i, count + i) = 1; |
|
91 d ((i - 1) * n + j, count + i) = 1; |
|
92 endfor |
|
93 count = count + n - j; |
|
94 endfor |
|
95 |
|
96 endfunction |