


function B = rand_matrix_normal(n, p, M, Omega_lower_chol, Sigma_lower_chol)
Pseudo random matrices drawn from a matrix-normal distribution
B ~ MN_n*p(M, Omega, Sigma)
Equivalent to vec(B) ~ N(vec(Mu), kron(Omega, Sigma))
INPUTS
n: row
p: column
M: (n*p) matrix, mean
Omega_lower_chol: (p*p), lower Cholesky decomposition of Omega,
(Omega_lower_chol = chol(Omega, 'lower'))
Sigma_lower_chol: (n*n), lower Cholesky decomposition of Sigma,
(Sigma_lower_chol = chol(Sigma, 'lower'))
OUTPUTS
B: (n*p) matrix drawn from a Matrix-normal distribution
SPECIAL REQUIREMENTS
Same notations than: http://en.wikipedia.org/wiki/Matrix_normal_distribution

0001 function B = rand_matrix_normal(n, p, M, Omega_lower_chol, Sigma_lower_chol) 0002 0003 % function B = rand_matrix_normal(n, p, M, Omega_lower_chol, Sigma_lower_chol) 0004 % Pseudo random matrices drawn from a matrix-normal distribution 0005 % B ~ MN_n*p(M, Omega, Sigma) 0006 % Equivalent to vec(B) ~ N(vec(Mu), kron(Omega, Sigma)) 0007 % 0008 % INPUTS 0009 % n: row 0010 % p: column 0011 % M: (n*p) matrix, mean 0012 % Omega_lower_chol: (p*p), lower Cholesky decomposition of Omega, 0013 % (Omega_lower_chol = chol(Omega, 'lower')) 0014 % Sigma_lower_chol: (n*n), lower Cholesky decomposition of Sigma, 0015 % (Sigma_lower_chol = chol(Sigma, 'lower')) 0016 % 0017 % OUTPUTS 0018 % B: (n*p) matrix drawn from a Matrix-normal distribution 0019 % 0020 % SPECIAL REQUIREMENTS 0021 % Same notations than: http://en.wikipedia.org/wiki/Matrix_normal_distribution 0022 0023 % Copyright (C) 2003-2009 Dynare Team 0024 % 0025 % This file is part of Dynare. 0026 % 0027 % Dynare is free software: you can redistribute it and/or modify 0028 % it under the terms of the GNU General Public License as published by 0029 % the Free Software Foundation, either version 3 of the License, or 0030 % (at your option) any later version. 0031 % 0032 % Dynare is distributed in the hope that it will be useful, 0033 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0034 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0035 % GNU General Public License for more details. 0036 % 0037 % You should have received a copy of the GNU General Public License 0038 % along with Dynare. If not, see <http://www.gnu.org/licenses/>. 0039 0040 B1 = randn(n * p, 1); 0041 B2 = kron(Omega_lower_chol, Sigma_lower_chol) * B1; 0042 B3 = reshape(B2, n, p); 0043 B = B3 + M;