Esempio n. 1
0
 private Matrix<double> NormalEqn(Matrix<double> X, Matrix<double> y)
 {
     // X*w = y
     // X'*X*w = X'*y
     // w = inv(X' * X) * X' * y
     return MatrixInverseExtensions.Inv3x3(X.Transpose * X) * X.Transpose * y;
 }
Esempio n. 2
0
        public void TestInv2x2()
        {
            var i3x3 = new Matrix <double>(new double[, ] {
                { 1.0, 0, 0 }, { 0, 1.0, 0 }, { 0, 0, 1.0 }
            });
            var i2x2 = new Matrix <double>(new double[, ] {
                { 1.0, 0.0 }, { 0.0, 1.0 }
            });

            // testing inverse
            var a = new Matrix <double>(new double[, ] {
                { 3, 0, 2 }, { 2, 0, -2 }, { 0, 1, 1 }
            });
            var a_inv = MatrixInverseExtensions.Inv3x3(a);
            var i     = a * a_inv;

            Assert.IsTrue(i == i3x3);

            // testing inverse
            a = new Matrix <double>(new double[, ] {
                { 1.0, 3.0 }, { 2.0, 1.0 }
            });
            a_inv = MatrixInverseExtensions.Inv2x2(a);
            i     = a * a_inv;
            //Assert.IsTrue(i == i2x2);

            //ii = new Matrix<double>(new double[,] { { 0.5, 0.75 }, { 1.3, 0.1 } });
            //ii_inv = inv2x2(ii);
            //i = ii * ii_inv;
            //Console.Write(i.ToString());

            //ii = new Matrix<double>(new double[,] { { 2, 5 }, { 1, 10 } });
            //ii_inv = inv2x2(ii);
            //i = ii * ii_inv;
            //Console.Write(i.ToString());
        }