I'm trying to make a simple random matrix multiplication program using the Eigen library in C++, but the numbers I get using the setRandom();
function are floats from -1 to 1 and I want for the numbers to be ints from 0 to 9 instead, how do I do that?
my code:
int mat_size;
cout << "Enter the size of the array: " << endl;
cin >> mat_size;
MatrixXd m = MatrixXd(mat_size,mat_size);
MatrixXd n = MatrixXd(mat_size,mat_size);
m.setRandom();
n.setRandom();
cout << "Matrix m: " << endl << m << endl;
cout << "Matrix n: " << endl << n << endl;
cout << "The product between m and n is: " << endl;
cout << m * n << endl;
and the output for a 3*3
matrix is always:
Matrix m:
0.680375 0.59688 -0.329554
-0.211234 0.823295 0.536459
0.566198 -0.604897 -0.444451
Matrix n:
0.10794 -0.270431 0.83239
-0.0452059 0.0268018 0.271423
0.257742 0.904459 0.434594
The product between m and n is:
-0.0384828 -0.466066 0.585123
0.0782496 0.564396 0.280774
-0.0260932 -0.571318 0.113959
I want for them to be something like:
matrix:
4 8 9
3 2 7
3 8 1