1 ## Copyright (C) 1995-2012 Kurt Hornik
2 ## Copyright (C) 2009 VZLU Prague
4 ## This file is part of Octave.
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
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
21 ## @deftypefn {Function File} {} vech (@var{x})
22 ## Return the vector obtained by eliminating all supradiagonal elements of
23 ## the square matrix @var{x} and stacking the result one column above the
24 ## other. This has uses in matrix calculus where the underlying matrix
25 ## is symmetric and it would be pointless to keep values above the main
30 ## See Magnus and Neudecker (1988), Matrix differential calculus with
31 ## applications in statistics and econometrics.
33 ## Author KH <Kurt.Hornik@wu-wien.ac.at>
34 ## Created: 8 May 1995
44 error ("vech: X must be square");
48 slices = cellslices (x(:), (1:n) + n*(0:n-1), n*(1:n));
49 v = vertcat (slices{:});
53 %!assert(all (vech ([1, 2, 3; 4, 5, 6; 7, 8, 9]) == [1; 4; 7; 5; 8; 9]));