I am really new with C++ but here is what I am trying to do. I have a 4 by 3 matrix:
100 109.523 119.096
100 89.7169 76.256
100 96.0822 103.246
100 101.084 85.0639
I want to take calculate the mean of each row and store it in some vector. I am using the Eigen library. I cannot think of anything to do this efficiently. Here is my code thus far:
MatrixXd SS(N,n+1);
MatrixXd Z = generateGaussianNoise(N,n);
for(int i = 0; i < N; i++){
SS(i,0) = S0;
for(int j = 1; j <= n; j++){
SS(i,j) = SS(i,j-1)*exp((double) (r - pow(sigma,2.0))*dt + sigma*sqrt(dt)*(double)Z(i,j-1));
}
}
cout << SS << endl;
cout << endl;
VectorXd S_A(3);
S_A = SS.row(1);
So what I have is a 4 by 3 matrix SS
and now I want to take the mean of each row and store it in the vector S_A
. I having a lot of difficulty with this, so any suggestions would be greatly appreciated.