static void TestMatrixVectorMultiplyCorrectness() { double[,] ATest = { { 1, 4 }, { 2, 5 }, { 3, 6 } }; double[] BTest = { 1, 2, 3 }; EigenWrapper.Matrix AMatTest = new EigenWrapper.Matrix(2, 3); EigenWrapper.Vector BVecTest = new EigenWrapper.Vector(3); //Set the values for the matrix validation tests AMatTest[0, 0] = 1; AMatTest[0, 1] = 2; AMatTest[0, 2] = 3; AMatTest[1, 0] = 4; AMatTest[1, 1] = 5; AMatTest[1, 2] = 6; BVecTest[0] = 1; BVecTest[1] = 2; BVecTest[2] = 3; //This doesn't test well because of the transposed interpretation of a 2D double array in the C# version //Testing the C# multiplcation accuracy //Console.WriteLine("C# matrix * vector correctness test:"); //Console.WriteLine("The input matrix is:"); //PrintMatrix(ATest); //Console.WriteLine("The input scalar is:"); //PrintVector(BTest); //Console.WriteLine("The result is:"); //double[,] Atrans = MatrixMathCS.Transpose(ATest); //double[] C = MatrixMathCS.VectorTimesMatrix(BTest, Atrans); //PrintVector(C); //Console.WriteLine(); //Test the Eigen multiplication accuracy Console.WriteLine("P/Invoke Eigen 2D double array matrix * vector correctness test:"); Console.WriteLine("The input matrix is:"); PrintMatrix(ATest); Console.WriteLine("The input scalar is:"); PrintVector(BTest); Console.WriteLine("The result is:"); double[] D = EigenWrapper.MatrixMath.MultiplyMatrixVector(ATest, BTest); PrintVector(D); Console.WriteLine(); //Test the Matrix class multiplication accuracy Console.WriteLine("P/Invoke Eigen matrix class matrix * vector correctness test:"); Console.WriteLine("The input matrix is:"); PrintMatrix(AMatTest); Console.WriteLine("The input scalar is:"); PrintVector(BVecTest); Console.WriteLine("The result is:"); EigenWrapper.Vector CVec = AMatTest * BVecTest; PrintVector(CVec); }
static void PrintVector(EigenWrapper.Vector vector) { Console.Write("{"); for (int i = 0; i < vector.Length; i++) { Console.Write(vector[i]); if (i < vector.Length - 1) { Console.Write(", "); } } Console.Write("}\r\n"); }
static void TestVectorCrossProduct() { double[] a = { 1, 0, 0 }; double[] b = { 0, 1, 0 }; EigenWrapper.Vector aVec = new EigenWrapper.Vector(3); EigenWrapper.Vector bVec = new EigenWrapper.Vector(3); aVec[0] = 1; aVec[1] = 0; aVec[2] = 0; bVec[0] = 0; bVec[1] = 1; bVec[2] = 0; //Test the Vector class cross product Console.WriteLine("C# vector cross product correctness test:"); Console.WriteLine("The first input vector is:"); PrintVector(a); Console.WriteLine("The second input vector is:"); PrintVector(b); Console.WriteLine("The cross product of a x b is:"); PrintVector(MatrixMathCS.CrossProduct(a, b)); Console.WriteLine(); //Test the Eigen cross product Console.WriteLine("P/Invoke Eigen double array cross product correctness test:"); Console.WriteLine("The first input vector is:"); PrintVector(a); Console.WriteLine("The second input vector is:"); PrintVector(b); Console.WriteLine("The cross product of a x b is:"); PrintVector(EigenWrapper.VectorMath.CrossProduct(a, b)); Console.WriteLine(); //Test the Vector class cross product Console.WriteLine("P/Invoke Eigen matrix class cross product correctness test:"); Console.WriteLine("The first input vector is:"); PrintVector(aVec); Console.WriteLine("The second input vector is:"); PrintVector(bVec); Console.WriteLine("The cross product of a x b is:"); PrintVector(aVec.CrossProduct(bVec)); }