Example #1
0
        //=====================================================================
        /// <summary>
        /// Metodo de Gauss-Jordan
        /// </summary>
        /// <param name="matrix"></param>
        internal static void EscalonadaReducidaPorFilas(Matrix matrix)
        {
            //1. Obtein the matrix EscalonadaPorFilas
            List <ElementalOperation.Data> inData;

            EscalonadaPorFilas(matrix, out inData);

            //2. With elemental operation III, make null the index up the pivote starting by the end
            for (int i = matrix.Rows - 1; i > 0; i--)
            {
                int pivoteIndex = Utilities.GetFirtsIndexNoNull(matrix, i);

                for (int k = i - 1; k > -1; k--)
                {
                    if (matrix[k, pivoteIndex] != 0)
                    {
                        ElementalOperation.Operation(matrix, ElementalOperation.Data.DataOperationIII(k, -matrix[k, pivoteIndex] / matrix[i, pivoteIndex], 0));
                    }
                }
            }

            //3. With elemental operation II, make 1 the pivote
            for (int i = 0; i > matrix.Rows; i++)
            {
                int pivoteIndex = Utilities.GetFirtsIndexNoNull(matrix, i);
                ElementalOperation.Operation(matrix, ElementalOperation.Data.DataOperationII(i, 1 / matrix[1, pivoteIndex]));
            }
        }
Example #2
0
        //=====================================================================
        /// <summary>
        /// Metodo de Gauss para la obtención de la matriz escalonada por filas
        /// </summary>
        /// <param name="matrix"></param>
        internal static void EscalonadaPorFilas(Matrix matrix, out List <ElementalOperation.Data> elementalOperantions)
        {
            elementalOperantions = new List <ElementalOperation.Data>();

            //1.With elemental operation I, order the row to obtain the first row with the index no null lower. The first input no null is called PIVOTE
            for (int i = 1; i < matrix.Rows; i++)
            {
                if (Utilities.GetFirtsIndexNoNull(matrix, i) < Utilities.GetFirtsIndexNoNull(matrix, i - 1))
                {
                    ElementalOperation.Data data = ElementalOperation.Data.DataOperationI(i, i - 1);
                    ElementalOperation.Operation(matrix, data);
                    elementalOperantions.Add(data);
                    i = Math.Max(0, i - 2);
                }
            }

            //2. With elemental operation III, make null the index down the pivote
            int pivoteIndex = Utilities.GetFirtsIndexNoNull(matrix, 0);

            if (!(pivoteIndex < matrix.Cols))
            {
                return;
            }

            for (int i = 1; i < matrix.Rows; i++)
            {
                if (matrix[i, pivoteIndex] != 0)
                {
                    ElementalOperation.Data data = ElementalOperation.Data.DataOperationIII(i, -matrix[i, pivoteIndex] / matrix[0, pivoteIndex], 0);
                    ElementalOperation.Operation(matrix, data);
                    elementalOperantions.Add(data);
                }
            }

            List <ElementalOperation.Data> inData;

            //3. Delete the first line and make the steps 1 and 3
            if (matrix.Rows > 1)
            {
                EscalonadaPorFilas(matrix[1, 0, matrix.Rows - 1, matrix.Cols], out inData);
                foreach (ElementalOperation.Data d in inData)
                {
                    elementalOperantions.Add(d);
                }
            }
        }