I am trying to create a function that basically copy's the matlab command: [z;-z]
where z = randn(m,n)
which returns an m-by-n matrix of random entries. I was able to create a function in C++ for the randn function which is below:
MatrixXd generateGaussianNoise(int n, int m){
MatrixXd M(n,m);
normal_distribution<double> nd(0.0, 1.0);
random_device rd;
mt19937 gen(rd());
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
M(i,j) = nd(gen);
}
}
return M;
}
Now I need to create the [z;-z]
function. For example let's say z = randn(2,2)
then the output will be:
-2.2588 0.3188
0.8622 -1.3077
Now when I write [z;-z]
we get:
-2.2588 0.3188
0.8622 -1.3077
2.2588 -0.3188
-0.8622 1.3077
What I am thinking is creating a function that taken in the matrix or vector z
store those entries in another matrix or vector and then create a new matrix or vector that is doubled in size to place the associated entries in the correct (i,j)
positions.
I am not sure if this is how I should proceed. Any comments or suggestions are greatly appreciated. As a side note, I am still a bit of a novice in C++.