Beispiel #1
0
        /// <inheritdoc/>
        public override string Print(RowElimOperNode node)
        {
            string cache;

            switch (node.EliminationMethod)
            {
            case RowElimMethod.Gauss: cache = @"\\ref"; break;

            case RowElimMethod.GaussJordan: cache = @"\\ref"; break;

            default: cache = string.Empty; break;
            }
            return($"{cache}{{{node.Child.Print(this)}}}");
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override ExpNode Execute(RowElimOperNode node)
        {
            // Ensure matrix.
            if (node.Child is TensorNode tensorNode && tensorNode.TensorType == TensorType.Matrix)
            {
                MatrixByRow matrix           = new MatrixByRow(tensorNode);
                int[]       leadingPositions = RefHelpers.GetLeadingColumns(matrix);

                // Put in row-echelon form
                for (int i = 0; i < matrix.Height; i++)
                {
                    int leftMostCol = RefHelpers.GetLeftMostColumn(leadingPositions, i);
                    matrix.SwapRows(i, leftMostCol);
                    Common.Swap(ref leadingPositions[i], ref leadingPositions[leftMostCol]);

                    if (leadingPositions[i] == -1)
                    {
                        continue;
                    }

                    matrix[i].MultiplyRow(QuickOpers.Reciprical(matrix[i][leadingPositions[i]]));
                    for (int j = i + 1; j < matrix.Height; j++)
                    {
                        matrix[j].AddRowToRow(matrix[i], QuickOpers.Negative(matrix[j][leadingPositions[i]]));
                        leadingPositions[j] = RefHelpers.GetLeadingColumn(matrix[j]);
                    }
                }

                if (node.EliminationMethod == RowElimMethod.GaussJordan)
                {
                    // Put in reduced row-echelon form
                    for (int i = matrix.Height - 1; i > 0; i--)
                    {
                        for (int j = i - 1; j >= 0; j--)
                        {
                            matrix[j].AddRowToRow(matrix[i], QuickOpers.Negative(matrix[j][leadingPositions[i]]));
                            leadingPositions[j] = RefHelpers.GetLeadingColumn(matrix[j]);
                        }
                    }
                }

                return(matrix.AsExpNode());
            }

            return(HandleError(new CannotReduceNonMatrix(this, node.Child)));
        }
Beispiel #3
0
 /// <summary>
 /// Executes operation on a <see cref="RowElimOperNode"/>.
 /// </summary>
 /// <param name="node">The <see cref="RowElimOperNode"/> to execute operation on.</param>
 /// <returns>The result of the operation on a <see cref="RowElimOperNode"/>.</returns>
 public virtual ExpNode Execute(RowElimOperNode node) => Execute((UOperNode)node);
Beispiel #4
0
 /// <summary>
 /// Prints a <see cref="RowElimOperNode"/>.
 /// </summary>
 /// <param name="node">The <see cref="RowElimOperNode"/> to print.</param>
 /// <returns>The <see cref="RowElimOperNode"/> printed to a string.</returns>
 public virtual string Print(RowElimOperNode node) => Print((UOperNode)node);