{"record":{"id":"58b207d126447070","repo":"TheAlgorithms/Java","slug":"max-eigenvalue-must-be-strictly-greater-than-min-e","errorCode":null,"errorMessage":"Max eigenvalue must be strictly greater than min eigenvalue.","messagePattern":"Max eigenvalue must be strictly greater than min eigenvalue\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/ChebyshevIteration.java","lineNumber":108,"sourceCode":"    private static void validateInputs(double[][] a, double[] b, double[] x0, double minEigenvalue, double maxEigenvalue, int maxIterations, double tolerance) {\n        int n = a.length;\n        if (n == 0) {\n            throw new IllegalArgumentException(\"Matrix A cannot be empty.\");\n        }\n        if (n != a[0].length) {\n            throw new IllegalArgumentException(\"Matrix A must be square.\");\n        }\n        if (n != b.length) {\n            throw new IllegalArgumentException(\"Matrix A and vector b dimensions do not match.\");\n        }\n        if (n != x0.length) {\n            throw new IllegalArgumentException(\"Matrix A and vector x0 dimensions do not match.\");\n        }\n        if (minEigenvalue <= 0) {\n            throw new IllegalArgumentException(\"Smallest eigenvalue must be positive (matrix must be positive-definite).\");\n        }\n        if (maxEigenvalue <= minEigenvalue) {\n            throw new IllegalArgumentException(\"Max eigenvalue must be strictly greater than min eigenvalue.\");\n        }\n        if (maxIterations <= 0) {\n            throw new IllegalArgumentException(\"Max iterations must be positive.\");\n        }\n        if (tolerance <= 0) {\n            throw new IllegalArgumentException(\"Tolerance must be positive.\");\n        }\n    }\n\n    // --- Vector/Matrix Helper Methods ---\n    /**\n     * Computes the product of a matrix A and a vector v (Av).\n     */\n    private static double[] matrixVectorMultiply(double[][] a, double[] v) {\n        int n = a.length;\n        double[] result = new double[n];\n        for (int i = 0; i < n; i++) {\n            double sum = 0;","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/ChebyshevIteration.java#L90-L126","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify maxEigenvalue > minEigenvalue and ensure correct argument order.","If eigenvalues are equal (degenerate matrix A = lambda*I), perturb slightly or use a direct solver instead.","Recompute eigenvalue bounds with a more precise method if the estimates are too close.","Double-check the parameter order in the method signature: (a, b, x0, minEigenvalue, maxEigenvalue, maxIterations, tolerance)."],"exampleFix":"// before\nChebyshevIteration.solve(A, b, x0, 5.0, 3.0, 100, 1e-6); // min=5 > max=3\n// throws 'Max eigenvalue must be strictly greater than min eigenvalue.'\n\n// after (correct argument order)\nChebyshevIteration.solve(A, b, x0, 3.0 /*min*/, 5.0 /*max*/, 100, 1e-6);","handlingStrategy":"validation","validationCode":"// Validate eigenvalue ordering before calling solve\nif (maxEigenvalue <= minEigenvalue) {\n    throw new IllegalArgumentException(\n        \"maxEigenvalue (\" + maxEigenvalue + \") must be > minEigenvalue (\" + minEigenvalue + \")\");\n}\ndouble[] x = ChebyshevIteration.solve(a, b, x0, minEig, maxEig, maxIter, tol);\n// For degenerate spectra (A = lambda*I), use a direct solver instead","typeGuard":"static boolean validSpectralInterval(double min, double max) {\n    return min > 0 && max > min;\n}","tryCatchPattern":null,"preventionTips":["Double-check argument order: minEigenvalue is parameter 4, maxEigenvalue is parameter 5.","If eigenvalues are very close, Chebyshev iteration converges slowly — consider an alternative.","For A = lambda*I (degenerate), the system is trivially solvable directly: x = b / lambda."],"tags":["linear-algebra","input-validation","eigenvalues","argument-order","chebyshev-iteration","java"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}