TheAlgorithms/Python · error · ValueError
The final value of x must be greater than initial value of x
Error message
The final value of x must be greater than initial value of x.
What it means
Error "The final value of x must be greater than initial value of x." thrown in TheAlgorithms/Python.
Source
Thrown at maths/numerical_analysis/runge_kutta_gills.py:61
>>> y
array([ 0. , -0.18, -0.32, -0.42, -0.48, -0.5 ])
>>> def f(x, y):
... return x + y
>>> y = runge_kutta_gills(f, 0, 0, 0.2, -1)
Traceback (most recent call last):
...
ValueError: The final value of x must be greater than initial value of x.
>>> def f(x, y):
... return x
>>> y = runge_kutta_gills(f, -1, 0, -0.2, 0)
Traceback (most recent call last):
...
ValueError: Step size must be positive.
"""
if x_initial >= x_final:
raise ValueError(
"The final value of x must be greater than initial value of x."
)
if step_size <= 0:
raise ValueError("Step size must be positive.")
n = int((x_final - x_initial) / step_size)
y = np.zeros(n + 1)
y[0] = y_initial
for i in range(n):
k1 = step_size * func(x_initial, y[i])
k2 = step_size * func(x_initial + step_size / 2, y[i] + k1 / 2)
k3 = step_size * func(
x_initial + step_size / 2,
y[i] + (-0.5 + 1 / sqrt(2)) * k1 + (1 - 1 / sqrt(2)) * k2,
)
k4 = step_size * func(
x_initial + step_size, y[i] - (1 / sqrt(2)) * k2 + (1 + 1 / sqrt(2)) * k3View on GitHub (pinned to f5988cc097)
Solutions
- Set the final x value greater than the initial x value.
- Swap the integration bounds if integrating in the reverse direction was intended.
When it happens
Trigger: Thrown at maths/numerical_analysis/runge_kutta_gills.py:61 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/db93ac39082352dd.
Report an issue: GitHub.