{"record":{"id":"db93ac39082352dd","repo":"TheAlgorithms/Python","slug":"the-final-value-of-x-must-be-greater-than-initial-db93ac","errorCode":null,"errorMessage":"The final value of x must be greater than initial value of x.","messagePattern":"The final value of x must be greater than initial value of x\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/numerical_analysis/runge_kutta_gills.py","lineNumber":61,"sourceCode":"    >>> y\n    array([ 0.  , -0.18, -0.32, -0.42, -0.48, -0.5 ])\n\n    >>> def f(x, y):\n    ...     return x + y\n    >>> y = runge_kutta_gills(f, 0, 0, 0.2, -1)\n    Traceback (most recent call last):\n        ...\n    ValueError: The final value of x must be greater than initial value of x.\n\n    >>> def f(x, y):\n    ...     return x\n    >>> y = runge_kutta_gills(f, -1, 0, -0.2, 0)\n    Traceback (most recent call last):\n        ...\n    ValueError: Step size must be positive.\n    \"\"\"\n    if x_initial >= x_final:\n        raise ValueError(\n            \"The final value of x must be greater than initial value of x.\"\n        )\n\n    if step_size <= 0:\n        raise ValueError(\"Step size must be positive.\")\n\n    n = int((x_final - x_initial) / step_size)\n    y = np.zeros(n + 1)\n    y[0] = y_initial\n    for i in range(n):\n        k1 = step_size * func(x_initial, y[i])\n        k2 = step_size * func(x_initial + step_size / 2, y[i] + k1 / 2)\n        k3 = step_size * func(\n            x_initial + step_size / 2,\n            y[i] + (-0.5 + 1 / sqrt(2)) * k1 + (1 - 1 / sqrt(2)) * k2,\n        )\n        k4 = step_size * func(\n            x_initial + step_size, y[i] - (1 / sqrt(2)) * k2 + (1 + 1 / sqrt(2)) * k3","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/numerical_analysis/runge_kutta_gills.py#L43-L79","documentation":"Error \"The final value of x must be greater than initial value of x.\" thrown in TheAlgorithms/Python.","triggerScenarios":"Thrown at maths/numerical_analysis/runge_kutta_gills.py:61 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the final x value greater than the initial x value.","Swap the integration bounds if integrating in the reverse direction was intended."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}