Ejemplo n.º 1
0
        public static int Rank(MMatrix A)
        {
            MMatrix temp = A.EchelonForm();
            int index = Math.Min(temp.row, temp.col);
            int rank = 0;

            for (int i = 0; i < index; ++i)
            {
                if (temp[i, i] != 0)
                    rank++;
            }

            return rank;
        }
        //Homogenious system: Solve A*x = 0
        public static Vector SolveSystemOfEquations(MMatrix A)
        {
            MMatrix Ref = new MMatrix();
            Vector x = new Vector(A.col);
            double sum;

            Ref = A.EchelonForm();
            for (int i = A.row - 1; i >= 0; i--)
            {
                //The system has more than one solutions. Get one.
                if (Ref[i, i] == 0)
                    x[i] = 1;
                else
                {
                    sum = 0;
                    for (int j = i + 1; j < Ref.col; ++j)
                    {
                        sum += Ref[i, j] * x[j];
                    }
                    x[i] = -sum / Ref[i, i];
                }
            }

            return x;
        }