Open the context
Choose the project folder and name the files or behavior involved.
Integrate scalar exponential decay with up to 1000 classical Runge–Kutta steps using finite bounded inputs. Check zero steps and zero rate, reject negative values for rate or step size and reject their product above one.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def decay_steps(initial, rate, dt, steps):
if any(type(v) not in (int, float) for v in (initial, rate, dt)):
raise ValueError("decay.numeric")
if not -10**6 <= initial <= 10**6 or not 0 <= rate <= 1000 or not 0 <= dt <= 1 or rate * dt > 1:
raise ValueError("decay.range")
if type(steps) is not int or not 0 <= steps <= 1000:
raise ValueError("decay.steps")
y = float(initial)
for _ in range(steps):
k1 = -rate * y
k2 = -rate * (y + dt*k1/2)
k3 = -rate * (y + dt*k2/2)
k4 = -rate * (y + dt*k3)
y += dt*(k1 + 2*k2 + 2*k3 + k4)/6
return yThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.