TheAlgorithms/Java · error · IllegalArgumentException

Max eigenvalue must be strictly greater than min eigenvalue.

Error message

Max eigenvalue must be strictly greater than min eigenvalue.

What it means

Thrown by ChebyshevIteration.validateInputs when maxEigenvalue <= minEigenvalue. The iteration parameters d = (max+min)/2 and c = (max-min)/2 require a valid spectral interval (min, max) where max is strictly greater than min. If max <= min, c would be zero or negative, making the Chebyshev polynomial parameters meaningless and preventing convergence.

Source

Thrown at src/main/java/com/thealgorithms/maths/ChebyshevIteration.java:108

    private static void validateInputs(double[][] a, double[] b, double[] x0, double minEigenvalue, double maxEigenvalue, int maxIterations, double tolerance) {
        int n = a.length;
        if (n == 0) {
            throw new IllegalArgumentException("Matrix A cannot be empty.");
        }
        if (n != a[0].length) {
            throw new IllegalArgumentException("Matrix A must be square.");
        }
        if (n != b.length) {
            throw new IllegalArgumentException("Matrix A and vector b dimensions do not match.");
        }
        if (n != x0.length) {
            throw new IllegalArgumentException("Matrix A and vector x0 dimensions do not match.");
        }
        if (minEigenvalue <= 0) {
            throw new IllegalArgumentException("Smallest eigenvalue must be positive (matrix must be positive-definite).");
        }
        if (maxEigenvalue <= minEigenvalue) {
            throw new IllegalArgumentException("Max eigenvalue must be strictly greater than min eigenvalue.");
        }
        if (maxIterations <= 0) {
            throw new IllegalArgumentException("Max iterations must be positive.");
        }
        if (tolerance <= 0) {
            throw new IllegalArgumentException("Tolerance must be positive.");
        }
    }

    // --- Vector/Matrix Helper Methods ---
    /**
     * Computes the product of a matrix A and a vector v (Av).
     */
    private static double[] matrixVectorMultiply(double[][] a, double[] v) {
        int n = a.length;
        double[] result = new double[n];
        for (int i = 0; i < n; i++) {
            double sum = 0;

View on GitHub (pinned to fdfb9a395b)

Solutions

  1. Verify maxEigenvalue > minEigenvalue and ensure correct argument order.
  2. If eigenvalues are equal (degenerate matrix A = lambda*I), perturb slightly or use a direct solver instead.
  3. Recompute eigenvalue bounds with a more precise method if the estimates are too close.
  4. Double-check the parameter order in the method signature: (a, b, x0, minEigenvalue, maxEigenvalue, maxIterations, tolerance).

Example fix

// before
ChebyshevIteration.solve(A, b, x0, 5.0, 3.0, 100, 1e-6); // min=5 > max=3
// throws 'Max eigenvalue must be strictly greater than min eigenvalue.'

// after (correct argument order)
ChebyshevIteration.solve(A, b, x0, 3.0 /*min*/, 5.0 /*max*/, 100, 1e-6);
Defensive patterns

Strategy: validation

Validate before calling

// Validate eigenvalue ordering before calling solve
if (maxEigenvalue <= minEigenvalue) {
    throw new IllegalArgumentException(
        "maxEigenvalue (" + maxEigenvalue + ") must be > minEigenvalue (" + minEigenvalue + ")");
}
double[] x = ChebyshevIteration.solve(a, b, x0, minEig, maxEig, maxIter, tol);
// For degenerate spectra (A = lambda*I), use a direct solver instead

Type guard

static boolean validSpectralInterval(double min, double max) {
    return min > 0 && max > min;
}

Prevention

When it happens

Trigger: Calling solve where maxEigenvalue == minEigenvalue (e.g., solve(A, b, x0, 3, 3, 100, 1e-6)), maxEigenvalue < minEigenvalue (e.g., solve(A, b, x0, 5, 3, ...)), or the two arguments are swapped.

Common situations: Swapping the minEigenvalue and maxEigenvalue arguments in the call (positional parameter confusion). Passing equal eigenvalues for a matrix with a degenerate spectrum (e.g., A = c*I). Using an eigenvalue estimator that returned the same value for both min and max due to precision or algorithm limitations.

Related errors


AI-assisted analysis of TheAlgorithms/Java@fdfb9a395b (2026-08-13). Data as JSON: /api/errors/58b207d126447070. Report an issue: GitHub.