Home > matlab > dyn_vech.m

dyn_vech

PURPOSE ^

This function implements the vech operator.

SYNOPSIS ^

function Vector = dyn_vech(Matrix)

DESCRIPTION ^

 This function implements the vech operator.
 
 INPUTS 
   Matrix             [double]   a squared n*n symetric matrix.
    
 OUTPUTS 
   Vector             [double]   a n*(n+1)/2 vector.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function Vector = dyn_vech(Matrix)
0002 % This function implements the vech operator.
0003 %
0004 % INPUTS
0005 %   Matrix             [double]   a squared n*n symetric matrix.
0006 %
0007 % OUTPUTS
0008 %   Vector             [double]   a n*(n+1)/2 vector.
0009 
0010 % Copyright (C) 2010 Dynare Team
0011 %
0012 % This file is part of Dynare.
0013 %
0014 % Dynare is free software: you can redistribute it and/or modify
0015 % it under the terms of the GNU General Public License as published by
0016 % the Free Software Foundation, either version 3 of the License, or
0017 % (at your option) any later version.
0018 %
0019 % Dynare is distributed in the hope that it will be useful,
0020 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0021 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0022 % GNU General Public License for more details.
0023 %
0024 % You should have received a copy of the GNU General Public License
0025 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0026 
0027 n = length(Matrix);
0028 b = 0;
0029 Vector = NaN(n*(n+1)/2,1);
0030 for col = 1:n
0031     idx = transpose(1:col);
0032     Vector(b+idx) = Matrix((col-1)*n+idx);
0033     b = b+length(idx);
0034 end

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005