{"record":{"id":"945dfb247a55a701","repo":"TheAlgorithms/Python","slug":"the-final-value-of-x-must-be-greater-than-initial","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_fehlberg_45.py","lineNumber":62,"sourceCode":"    >>> y = runge_kutta_fehlberg_45(5, 0, 0, 0.1, 1)\n    Traceback (most recent call last):\n        ...\n    TypeError: 'int' object is not callable\n    >>> def f(x, y):\n    ...     return x + y\n    >>> y = runge_kutta_fehlberg_45(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    >>> def f(x, y):\n    ...     return x\n    >>> y = runge_kutta_fehlberg_45(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        (n + 1),\n    )\n    x = np.zeros(n + 1)\n    y[0] = y_initial\n    x[0] = x_initial\n    for i in range(n):\n        k1 = step_size * func(x[i], y[i])\n        k2 = step_size * func(x[i] + step_size / 4, y[i] + k1 / 4)\n        k3 = step_size * func(\n            x[i] + (3 / 8) * step_size, y[i] + (3 / 32) * k1 + (9 / 32) * k2","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/numerical_analysis/runge_kutta_fehlberg_45.py#L44-L80","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_fehlberg_45.py:62 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-15T22:17:37.221Z"}