posted on: 2019-10-08 08:06:21
This is a short test to try out eigen, and create some notes.
The first thing is the multiplication test. What is the matrix ordering.
We populate a new matrix with k(slow, fast) iterations.
for(int i = 0; i<9; i++){ k(i/3, i%3) = i*0.1; }
So if we print our matrix k(i, j), where j is fast we should get a counting right to left across rows. 1, 2 \n 3, 4. Then we create a vector to check the multiplication.
Vector3d v1(0.5, 0.25, 0.125); VectorXd v2 = k*v1; for(int i = 0; i<3; i++){ for(int j = 0; j<3; j++){ printf("%f\t", k(i, j)); } printf("%f\t: %f\n", v1(i), v2(i)); }
The output is as we expect:
0.000000 0.100000 0.200000 0.500000 : 0.050000 0.300000 0.400000 0.500000 0.250000 : 0.312500 0.600000 0.700000 0.800000 0.125000 : 0.575000
First index is the row.
Does assigning/mapping 1D arrays to matrixes do the same order? Is matrix-matrix multiplication as we expect. m1(3,3) * m2(3, 2) = m3(3, 2)?
MatrixXd k2(3,2); k2 << 0.1, 0.2, 0.3, 0.4, 0.5, 0.6; MatrixXd o = k * k2; for(int i = 0; i<3; i++){ for(int j = 0; j<3; j++){ printf("%f\t", k(i, j)); } printf("| %f, %f\t: %f, %f\n", k2(i, 0), k2(i, 1), o(i, 0), o(i, 1)); }
Produces the following output.
0.000000 0.100000 0.200000 | 0.100000, 0.200000 : 0.130000, 0.160000 0.300000 0.400000 0.500000 | 0.300000, 0.400000 : 0.400000, 0.520000 0.600000 0.700000 0.800000 | 0.500000, 0.600000 : 0.670000, 0.880000
Comments
create comment?