Multiply() 공개 정적인 메소드

Multiply two matrixes.
public static Multiply ( Matrix a, Matrix b ) : Matrix
a Matrix The first matrix.
b Matrix The second matrix.
리턴 Matrix
예제 #1
0
        public void Multiply()
        {
            double[][] matrixData1 =
            {
                new[] { 1.0, 4.0 },
                new[] { 2.0, 5.0 },
                new[] { 3.0, 6.0 }
            };
            double[][] matrixData2 =
            {
                new[] {  7.0,  8.0,  9.0 },
                new[] { 10.0, 11.0, 12.0 }
            };


            double[][] matrixData3 =
            {
                new[] { 47.0, 52.0, 57.0 },
                new[] { 64.0, 71.0, 78.0 },
                new[] { 81.0, 90.0, 99.0 }
            };

            var matrix1 = new Matrix(matrixData1);
            var matrix2 = new Matrix(matrixData2);

            var matrix3 = new Matrix(matrixData3);

            Matrix result = MatrixMath.Multiply(matrix1, matrix2);

            Assert.IsTrue(result.Equals(matrix3));
        }
예제 #2
0
        public void MultiplyScalar()
        {
            double[][] data =
            {
                new[] { 2.0, 4.0 },
                new[] { 6.0, 8.0 }
            };
            var    matrix = new Matrix(data);
            Matrix result = MatrixMath.Multiply(matrix, 2.0);

            Assert.AreEqual(4.0, result[0, 0]);
        }
예제 #3
0
        public void MatrixMultiply()
        {
            double[][] a =
            {
                new[] {  1.0, 0.0, 2.0 },
                new[] { -1.0, 3.0, 1.0 }
            };

            double[][] b =
            {
                new[] { 3.0, 1.0 },
                new[] { 2.0, 1.0 },
                new[] { 1.0, 0.0 }
            };

            double[][] c =
            {
                new[] { 5.0, 1.0 },
                new[] { 4.0, 2.0 }
            };

            var matrixA = new Matrix(a);
            var matrixB = new Matrix(b);
            var matrixC = new Matrix(c);

            var result = (Matrix)matrixA.Clone();

            result.ToString();
            result = MatrixMath.Multiply(matrixA, matrixB);

            Assert.IsTrue(result.Equals(matrixC));

            double[][] a2 =
            {
                new[] { 1.0, 2.0, 3.0, 4.0 },
                new[] { 5.0, 6.0, 7.0, 8.0 }
            };

            double[][] b2 =
            {
                new[] {  1.0,  2.0,  3.0 },
                new[] {  4.0,  5.0,  6.0 },
                new[] {  7.0,  8.0,  9.0 },
                new[] { 10.0, 11.0, 12.0 }
            };

            double[][] c2 =
            {
                new[] {  70.0,  80.0,  90.0 },
                new[] { 158.0, 184.0, 210.0 }
            };

            matrixA = new Matrix(a2);
            matrixB = new Matrix(b2);
            matrixC = new Matrix(c2);

            result = MatrixMath.Multiply(matrixA, matrixB);
            Assert.IsTrue(result.Equals(matrixC));

            matrixB.Clone();

            try
            {
                MatrixMath.Multiply(matrixB, matrixA);
                Assert.IsTrue(false);
            }
            catch (MatrixError)
            {
            }
        }