How to generate a multivariate normal distribution?

Apr 5, 2012 at 5:07 PM

Hey, I am new to C#. I am trying to sample a matrix from a multivariate normal distribution, I applied the class Matrix Normal, but I found that it only works for the matrix where the number of rows is the same with the number of columns. For example, if I run the following code:

var NRow = 3;
var NCol = 3;
var m = new DenseMatrix(NRow, NCol);
var v = new DenseMatrix(NRow);
for (var i = 0; i < NRow; i++)
{
    v[i, i] = 1;
}
var k = new DenseMatrix(NCol);
for (var i = 0; i < NCol; i++)
{
    k[i, i] = 1;
}            
var NewMatrix = new MatrixNormal(m, v, k);
var Sampleone = NewMatrix.Sample();
It works, however, when I change NRow=4, it does not work. Anyone can help me with this?