Ejemplo n.º 1
0
        public void CorrectlyMultiplyByVector()
        {
            var values = new[]
                {
                    new[] {new RealNumber(1.0), new RealNumber(2.0), new RealNumber(3.0)},
                    new[] {new RealNumber(1.0), new RealNumber(2.0), new RealNumber(3.0)},
                    new[] {new RealNumber(0.0), new RealNumber(0.0), new RealNumber(4.0)},
                    new[] {new RealNumber(0.0), new RealNumber(1.0), new RealNumber(0.0)},
                };
            var matrix = new Matrix(values);
            var vector =
                new Vector(new[]
                    {
                        new RealNumber(1.0), new RealNumber(2.0), new RealNumber(1.0)
                    });

            var expected = new[]
                {
                    new RealNumber(8.0), new RealNumber(8.0), new RealNumber(4.0), new RealNumber(2.0)
                };

            var result = matrix.Mul(vector);

            Assert.That(result.Length, Is.EqualTo(matrix.Rows));
            for (int i = 0; i < result.Length; i++)
                Assert.That(result[i].GetMod().X, Is.EqualTo(expected[i].GetMod().X));
        }
Ejemplo n.º 2
0
        public void CorrectlyMulMatrixes()
        {
            var valuesX = new[]
                {
                    new[] {new RealNumber(1.0), new RealNumber(2.0), new RealNumber(3.0)},
                    new[] {new RealNumber(-1.0), new RealNumber(2.0), new RealNumber(3.0)},
                    new[] {new RealNumber(1.0), new RealNumber(2.0), new RealNumber(3.0)},
                    new[] {new RealNumber(1.0), new RealNumber(2.0), new RealNumber(3.0)},
                };
            var matrixX = new Matrix(valuesX);
            var valuesY = new[]
                {
                    new[] {new RealNumber(1.0), new RealNumber(2.0)},
                    new[] {new RealNumber(1.0), new RealNumber(2.0)},
                    new[] {new RealNumber(1.0), new RealNumber(2.0)},
                };
            var matrixY = new Matrix(valuesY);
            var results = new[]
                {
                    new[] {new RealNumber(6.0), new RealNumber(12.0)},
                    new[] {new RealNumber(4.0), new RealNumber(8.0)},
                    new[] {new RealNumber(6.0), new RealNumber(12.0)},
                    new[] {new RealNumber(6.0), new RealNumber(12.0)},
                };

            var result = matrixX.Mul(matrixY);

            for (int i = 0; i < matrixX.Rows; i++)
                for (int j = 0; j < matrixY.Columns; j++)
                    Assert.That(result[i, j].GetMod().X, Is.EqualTo(results[i][j].GetMod().X));
        }
Ejemplo n.º 3
0
        public void CorrectlyMultiplyByFuzzyNumber()
        {
            var values = new[]
                {
                    new[] {new RealNumber(2.0), new RealNumber(2.0), new RealNumber(4.0)},
                    new[] {new RealNumber(4.0), new RealNumber(6.0), new RealNumber(6.0)},
                    new[] {new RealNumber(8.0), new RealNumber(8.0), new RealNumber(10.0)},
                    new[] {new RealNumber(10.0), new RealNumber(12.0), new RealNumber(12.0)},
                };
            var matrix = new Matrix(values);
            var multiplier = new RealNumber(-0.5);
            var results = new[]
                {
                    new[] {new RealNumber(-1.0), new RealNumber(-1.0), new RealNumber(-2.0)},
                    new[] {new RealNumber(-2.0), new RealNumber(-3.0), new RealNumber(-3.0)},
                    new[] {new RealNumber(-4.0), new RealNumber(-4.0), new RealNumber(-5.0)},
                    new[] {new RealNumber(-5.0), new RealNumber(-6.0), new RealNumber(-6.0)},
                };

            var result = matrix.Mul(multiplier);

            for (int i = 0; i < matrix.Rows; i++)
                for (int j = 0; j < matrix.Columns; j++)
                    Assert.That(result[i, j].GetMod().X, Is.EqualTo(results[i][j].GetMod().X));
        }