コード例 #1
0
        public void Determinant2x2()
        {
            var b = new RTF.Matrix(2, 2);

            b.SetRow(0, new double[] { 1, 5 });
            b.SetRow(1, new double[] { -3, 2 });

            Assert.Equal(17, b.Determinant());
        }
コード例 #2
0
        public void Determinant4x4()
        {
            var e = new RTF.Matrix(4, 4);

            e.SetRow(0, new double[] { -2, -8, 3, 5 });
            e.SetRow(1, new double[] { -3, 1, 7, 3 });
            e.SetRow(2, new double[] { 1, 2, -9, 6 });
            e.SetRow(3, new double[] { -6, 7, 7, -9 });

            Assert.Equal(690, RTF.Matrix.Cofactor(e, 0, 0));
            Assert.Equal(447, RTF.Matrix.Cofactor(e, 0, 1));
            Assert.Equal(210, RTF.Matrix.Cofactor(e, 0, 2));
            Assert.Equal(51, RTF.Matrix.Cofactor(e, 0, 3));
            Assert.Equal(-4071, e.Determinant());
        }
コード例 #3
0
        public void Inverse()
        {
            var e = new RTF.Matrix(4, 4);

            e.SetRow(0, new double[] { -5, 2, 6, -8 });
            e.SetRow(1, new double[] { 1, -5, 1, 8 });
            e.SetRow(2, new double[] { 7, 7, -6, -7 });
            e.SetRow(3, new double[] { 1, -3, 7, 4 });

            double r1 = -160d / 532;
            double r2 = 105d / 532;
            var    b  = e.Inverse();

            Assert.Equal(532, e.Determinant());
            Assert.Equal(-160, RTF.Matrix.Cofactor(e, 2, 3));
            Assert.Equal(r1, b[3, 2]);
            Assert.Equal(105, RTF.Matrix.Cofactor(e, 3, 2));
            Assert.Equal(r2, b[2, 3]);
        }