{"record":{"id":"625beb35d74291fc","repo":"TheAlgorithms/Java","slug":"xend-should-be-greater-than-xstart","errorCode":null,"errorMessage":"xEnd should be greater than xStart","messagePattern":"xEnd should be greater than xStart","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/EulerMethod.java","lineNumber":79,"sourceCode":"        }\n        return yCurrent + stepSize * differentialEquation.apply(xCurrent, yCurrent);\n    }\n\n    /**\n     * Loops through all the steps until xEnd is reached, adds a point for each\n     * step and then returns all the points\n     *\n     * @param xStart First x-value.\n     * @param xEnd Last x-value.\n     * @param stepSize Step-size on the x-axis.\n     * @param yStart First y-value.\n     * @param differentialEquation The differential equation to be solved.\n     * @return The points constituting the solution of the differential\n     * equation.\n     */\n    public static ArrayList<double[]> eulerFull(double xStart, double xEnd, double stepSize, double yStart, BiFunction<Double, Double, Double> differentialEquation) {\n        if (xStart >= xEnd) {\n            throw new IllegalArgumentException(\"xEnd should be greater than xStart\");\n        }\n        if (stepSize <= 0) {\n            throw new IllegalArgumentException(\"stepSize should be greater than zero\");\n        }\n\n        ArrayList<double[]> points = new ArrayList<double[]>();\n        double[] firstPoint = {xStart, yStart};\n        points.add(firstPoint);\n        double yCurrent = yStart;\n        double xCurrent = xStart;\n\n        while (xCurrent < xEnd) {\n            // Euler's method for next step\n            yCurrent = eulerStep(xCurrent, stepSize, yCurrent, differentialEquation);\n            xCurrent += stepSize;\n            double[] point = {xCurrent, yCurrent};\n            points.add(point);\n        }","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/EulerMethod.java#L61-L97","documentation":"Thrown by EulerMethod.eulerFull when xStart >= xEnd. eulerFull integrates forward from xStart to xEnd in steps of stepSize; if the start is not strictly before the end, the while(xCurrent < xEnd) loop would never execute (or run zero times) and the integration direction would be ill-defined. The library treats a non-increasing interval as invalid rather than returning a single-point result.","triggerScenarios":"Calling eulerFull with xStart equal to xEnd, xStart greater than xEnd (e.g. integrating backward), or with bounds derived from input where the order is reversed.","commonSituations":"Swapped start/end arguments; bounds read from a config where the upper bound was defaulted to 0; integrating over a degenerate interval; sign error in computing the end point.","solutions":["Ensure xEnd > xStart, e.g. eulerFull(0.0, 1.0, 0.1, y0, f).","If you need backward integration, swap the bounds and negate the step, or use a method that supports it.","Validate the interval at the caller and surface a clear message if inverted."],"exampleFix":"// before\nEulerMethod.eulerFull(1.0, 1.0, 0.1, y0, f); // xStart == xEnd\n\n// after\nEulerMethod.eulerFull(0.0, 1.0, 0.1, y0, f);","handlingStrategy":"validation","validationCode":"if (!(xEnd > xStart)) {\n    throw new IllegalArgumentException(\"require xEnd > xStart\");\n}\nEulerMethod.eulerFull(xStart, xEnd, stepSize, yStart, f);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify interval ordering before integrating; swap if needed.","For backward integration, use a method that supports it rather than inverting bounds silently.","Validate bounds read from config where the upper bound may default to 0."],"tags":["validation","numerical-methods","ode","precondition"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}