SGVM_MULT_RANDN sample N times from a multivariate normal distribution Z = SGVM_MULT_RANDN(N, SIGMA, MU) Sample N times from a multivariate normal distribution with covariance matrix SIGMA and mean vector MU basically copied from the RAND help documentation example
0001 function z = sgvm_mult_randn(n, sigma, mu) 0002 %SGVM_MULT_RANDN sample N times from a multivariate normal distribution 0003 % Z = SGVM_MULT_RANDN(N, SIGMA, MU) 0004 % 0005 % Sample N times from a multivariate normal distribution 0006 % with covariance matrix SIGMA and mean vector MU 0007 % basically copied from the RAND help documentation example 0008 0009 % SynGrid 0010 % Copyright (c) 2018, Power Systems Engineering Research Center (PSERC) 0011 % by Eran Schweitzer, Arizona State University 0012 % 0013 % This file is part of SynGrid. 0014 % Covered by the 3-clause BSD License (see LICENSE file for details). 0015 0016 d = size(sigma,1); 0017 if nargin == 2 0018 mu = zeros(1,d); 0019 end 0020 mu = sgvm_ensure_col_vect(mu).'; 0021 0022 R = chol(sigma); 0023 0024 z = repmat(mu,n,1) + randn(n, d)*R;