8920
|
1 ## Copyright (C) 1995, 1996, 1997, 1999, 2000, 2002, 2005, 2006, 2007, 2008 |
7017
|
2 ## Kurt Hornik |
9093
|
3 ## Copyright (C) 2009 VZLU Prague |
3426
|
4 ## |
3922
|
5 ## This file is part of Octave. |
|
6 ## |
|
7 ## Octave is free software; you can redistribute it and/or modify it |
|
8 ## under the terms of the GNU General Public License as published by |
7016
|
9 ## the Free Software Foundation; either version 3 of the License, or (at |
|
10 ## your option) any later version. |
3426
|
11 ## |
3922
|
12 ## Octave is distributed in the hope that it will be useful, but |
2540
|
13 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
15 ## General Public License for more details. |
|
16 ## |
2540
|
17 ## You should have received a copy of the GNU General Public License |
7016
|
18 ## along with Octave; see the file COPYING. If not, see |
|
19 ## <http://www.gnu.org/licenses/>. |
2540
|
20 |
3369
|
21 ## -*- texinfo -*- |
|
22 ## @deftypefn {Function File} {} vech (@var{x}) |
|
23 ## Return the vector obtained by eliminating all supradiagonal elements of |
|
24 ## the square matrix @var{x} and stacking the result one column above the |
|
25 ## other. |
|
26 ## @end deftypefn |
|
27 |
2540
|
28 ## See Magnus and Neudecker (1988), Matrix differential calculus with |
|
29 ## applications in statistics and econometrics. |
|
30 |
5428
|
31 ## Author KH <Kurt.Hornik@wu-wien.ac.at> |
2540
|
32 ## Created: 8 May 1995 |
|
33 ## Adapted-By: jwe |
|
34 |
|
35 function v = vech (x) |
3426
|
36 |
2540
|
37 if (nargin != 1) |
6046
|
38 print_usage (); |
2540
|
39 endif |
3426
|
40 |
4030
|
41 if (! issquare (x)) |
3458
|
42 error ("vech: x must be square"); |
2540
|
43 endif |
3426
|
44 |
2540
|
45 n = rows (x); |
9093
|
46 slices = cellslices (x(:), (1:n) + n*(0:n-1), n*(1:n)); |
|
47 v = vertcat (slices{:}); |
2540
|
48 |
|
49 endfunction |
7411
|
50 |
|
51 %!assert(all (vech ([1, 2, 3; 4, 5, 6; 7, 8, 9]) == [1; 4; 7; 5; 8; 9])); |
|
52 |
|
53 %!error vech (); |
|
54 |
|
55 %!error vech (1, 2); |
|
56 |