TheAlgorithms/C-Sharp · error · ArgumentException

Please use a n*(n+1) matrix with Length > 0.

Error message

Please use a n*(n+1) matrix with Length > 0.

What it means

Solve validates the matrix via CanMatrixBeUsed before solving; this ArgumentException fires when the matrix is not a non-empty n*(n+1) augmented matrix, the only shape a linear system solvable by Gauss-Jordan has.

Solutions

  1. Reshape the input to an n x (n+1) matrix: the n coefficients of each equation plus the right-hand-side constant in the last column, and at least 2 rows.
  2. Ensure the matrix is non-empty (Length > 0) and element [i, n] holds the constant term of equation i before calling Solve.

When it happens

Trigger: Thrown at Algorithms/Numeric/GaussJordanElimination.cs:24 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of TheAlgorithms/C-Sharp@96e2905cab (2026-09-13). Data as JSON: /api/errors/4d98e554db1ef5ce. Report an issue: GitHub.

Appendix: source

Thrown at Algorithms/Numeric/GaussJordanElimination.cs:24

public class GaussJordanElimination
{
    private int RowCount { get; set; }

    /// <summary>
    ///     Method to find a linear equation system using gaussian elimination.
    /// </summary>
    /// <param name="matrix">The key matrix to solve via algorithm.</param>
    /// <returns>
    ///     whether the input matrix has a unique solution or not.
    ///     and solves on the given matrix.
    /// </returns>
    public bool Solve(double[,] matrix)
    {
        RowCount = matrix.GetUpperBound(0) + 1;

        if (!CanMatrixBeUsed(matrix))
        {
            throw new ArgumentException("Please use a n*(n+1) matrix with Length > 0.");
        }

        var pivot = PivotMatrix(ref matrix);
        if (!pivot)
        {
            return false;
        }

        Elimination(ref matrix);

        return ElementaryReduction(ref matrix);
    }

    /// <summary>
    ///     To make simple validation of the matrix to be used.
    /// </summary>
    /// <param name="matrix">Multidimensional array matrix.</param>
    /// <returns>

View on GitHub (pinned to 96e2905cab)