MultiplyBy() public méthode

Returns the product matrix of this matrix multiplied by the passed matrix, in that order.
public MultiplyBy ( Matrix passedMatrix ) : Matrix
passedMatrix Matrix
Résultat Matrix
        public void Matrix_StandardMatrixMultiplyTest()
        {
            Matrix matrix1 = new Matrix(3, 2);
            matrix1.SetElement(0, 0, 1);
            matrix1.SetElement(0, 1, 1);
            matrix1.SetElement(1, 0, 2);
            matrix1.SetElement(1, 1, 0);
            matrix1.SetElement(2, 0, 0);
            matrix1.SetElement(2, 1, 3);

            Matrix matrix2 = new Matrix(2, 4);
            matrix2.SetElement(0, 0, 0);
            matrix2.SetElement(0, 1, 1);
            matrix2.SetElement(0, 2, 1);
            matrix2.SetElement(0, 3, 0);
            matrix2.SetElement(1, 0, 2);
            matrix2.SetElement(1, 1, 3);
            matrix2.SetElement(1, 2, 0);
            matrix2.SetElement(1, 3, 1);

            Matrix answerMatrix = new Matrix(3, 4);
            answerMatrix.SetElement(0, 0, 2);
            answerMatrix.SetElement(0, 1, 4);
            answerMatrix.SetElement(0, 2, 1);
            answerMatrix.SetElement(0, 3, 1);
            answerMatrix.SetElement(1, 0, 0);
            answerMatrix.SetElement(1, 1, 2);
            answerMatrix.SetElement(1, 2, 2);
            answerMatrix.SetElement(1, 3, 0);
            answerMatrix.SetElement(2, 0, 6);
            answerMatrix.SetElement(2, 1, 9);
            answerMatrix.SetElement(2, 2, 0);
            answerMatrix.SetElement(2, 3, 3);

            Matrix resultingMatrix = matrix1.MultiplyBy(matrix2);

            bool answer = (resultingMatrix == answerMatrix);
            answer.Should().BeTrue();

        }
        public void PseudoInvSolveTest()
        {
            double[,] a = { { 0, 0 }, { 0,2 } };
            double[,] P;
            P=Matrix.GetPseudoInverse(a);
            double[] b = { 0, 1 };
            var x = Matrix.PseudoInvSolve(P, b);
            var testResult = new Matrix(2, 2);

            testResult.SetColumn(0, a.GetColumn(0));
            testResult.SetColumn(1, a.GetColumn(1));
           

            var tX = new Matrix(x);
            var tB = new Matrix(b);

            (testResult.MultiplyBy(tX) == tB).Should().BeTrue();


        }
        public void LUSolveTest()
        {
            double[,] a = {{4, 1, 1, 1}, {-1, 2, 1, 1}, {1, 1, 2, 2}, {1, 1, 2, 4}};
            double[,] l, u;
            Matrix.LUDecomp(a, out l, out u);
            double[] b = {2.4, 1.4, 1.7, 25};
            var x=Matrix.LUSolve(l, u, b);
            var testResult=new Matrix(4,4);
            
            testResult.SetColumn(0, a.GetColumn(0));
            testResult.SetColumn(1, a.GetColumn(1));
            testResult.SetColumn(2, a.GetColumn(2));
            testResult.SetColumn(3, a.GetColumn(3));

            var tX=new Matrix(x);
            var tB=new Matrix(b);

            (testResult.MultiplyBy(tX)==tB).Should().BeTrue();


        }
        public void Matrix_IdentityMatrixMultiplyTest()
        {
            Matrix matrix1 = new Matrix(3, 2);
            matrix1.SetElement(0, 0, 1);
            matrix1.SetElement(0, 1, 1);
            matrix1.SetElement(1, 0, 2);
            matrix1.SetElement(1, 1, 0);
            matrix1.SetElement(2, 0, 0);
            matrix1.SetElement(2, 1, 3);

            Matrix matrix2 = new Matrix(2, 2);
            matrix2.SetElement(0, 0, 1);
            matrix2.SetElement(0, 1, 0);
            matrix2.SetElement(1, 0, 0);
            matrix2.SetElement(1, 1, 1);

            Matrix resultingMatrix = matrix1.MultiplyBy(matrix2);

            bool answer = (resultingMatrix == matrix1);
            answer.Should().BeTrue();

        }