/// <summary>
        /// Eliminate a row.
        /// </summary>
        /// <param name="pivot">The current pivot.</param>
        private void Elimination(MatrixElement <Complex> pivot)
        {
            // Test for zero pivot
            if (pivot.Value.Equals(0.0))
            {
                throw new SparseException("Matrix is singular");
            }
            pivot.Value = 1.0 / pivot.Value; // Inverse(pivot.Value);

            var upper = pivot.Right;

            while (upper != null)
            {
                // Calculate upper triangular element
                // upper = upper / pivot
                upper.Value *= pivot.Value;

                var sub   = upper.Below;
                var lower = pivot.Below;
                while (lower != null)
                {
                    var row = lower.Row;

                    // Find element in row that lines up with the current lower triangular element
                    while (sub != null && sub.Row < row)
                    {
                        sub = sub.Below;
                    }

                    // Test to see if the desired element was not found, if not, create fill-in
                    if (sub == null || sub.Row > row)
                    {
                        sub = CreateFillin(row, upper.Column);
                    }

                    // element -= upper * lower
                    sub.Value -= upper.Value * lower.Value;
                    sub        = sub.Below;
                    lower      = lower.Below;
                }
                upper = upper.Right;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Move a chosen pivot to the diagonal.
        /// </summary>
        /// <param name="pivot">The pivot element.</param>
        /// <param name="step">The current step of factoring.</param>
        public void MovePivot(MatrixElement <T> pivot, int step)
        {
            pivot.ThrowIfNull(nameof(pivot));
            Strategy.MovePivot(Matrix, Rhs, pivot, step);

            // Move the pivot in the matrix
            var row    = pivot.Row;
            var column = pivot.Column;

            if (row != step)
            {
                SwapRows(row, step);
            }
            if (column != step)
            {
                SwapColumns(column, step);
            }

            // Update the pivoting strategy
            Strategy.Update(Matrix, pivot, step);
        }
Beispiel #3
0
        /// <summary>
        /// Move a chosen pivot to the diagonal
        /// </summary>
        /// <param name="pivot">Pivot</param>
        /// <param name="step">Step</param>
        public void MovePivot(MatrixElement <T> pivot, int step)
        {
            if (pivot == null)
            {
                throw new ArgumentNullException(nameof(pivot));
            }
            Strategy.MovePivot(Matrix, Rhs, pivot, step);

            // Move the pivot in the matrix
            int row    = pivot.Row;
            int column = pivot.Column;

            if (row != step)
            {
                SwapRows(row, step);
            }
            if (column != step)
            {
                SwapColumns(column, step);
            }

            Strategy.Update(Matrix, pivot, step);
        }