Exemplo n.º 1
0
        public MatrisBase <object> RREchelon(MatrisBase <object> A)
        {
            // Bad dimensions
            if (!A.IsValid())
            {
                throw new Exception(CompilerMessage.MAT_INVALID_SIZE);
            }

            // Zero matrix
            if (A.IsZero((float)0.0))
            {
                return(A);
            }

            if (A is Dataframe df)
            {
                CompilerUtils.AssertMatrixValsAreNumbers(A);

                Dataframe result = df.Copy();
                InnerRREchelon(df, result);
                return(result);
            }
            else
            {
                MatrisBase <object> result = A.Copy();
                InnerRREchelon(A, result);
                return(result);
            }
        }
Exemplo n.º 2
0
        public float Determinant(MatrisBase <object> A)
        {
            if (!A.IsSquare())
            {
                throw new Exception(CompilerMessage.MAT_NOT_SQUARE);
            }

            if (A.IsZero((float)0.0))
            {
                CompilerUtils.AssertMatrixValsAreNumbers(A);
                return((float)0.0);
            }

            if (A.Row == 1)
            {
                CompilerUtils.AssertMatrixValsAreNumbers(A);
                return(float.Parse(A.GetValues()[0][0].ToString()));
            }

            if (A.Row == 2)
            {
                CompilerUtils.AssertMatrixValsAreNumbers(A);
                return((float.Parse(A.GetValues()[0][0].ToString()) * float.Parse(A.GetValues()[1][1].ToString()))
                       - (float.Parse(A.GetValues()[0][1].ToString()) * float.Parse(A.GetValues()[1][0].ToString())));
            }

            using MatrisBase <object> ech = Echelon(A.Copy());

            float det = float.Parse(ech.GetValues()[0][0].ToString());

            if (ech.SwapCount % 2 == 1)
            {
                det *= -1;
            }

            int dim = A.Row;

            for (int i = 1; i < dim; i++)
            {
                det *= float.Parse(ech.GetValues()[i][i].ToString());
            }
            return(det);
        }