Runge-Kutta 4 single-step calculator
This Runge-Kutta 4 single-step calculator advances a first-order differential equation from one known point to the next.
Run — free
Enter the derivative as f(x, y), the starting coordinates, and a nonzero step size. The result shows k1, k2, k3, and k4 as slope estimates, the intermediate points where they are evaluated, their weighted average, and the final RK4 approximation. That complete trail makes the calculator useful for checking homework, validating a numerical solver, or documenting one step without hiding the arithmetic.
Describe the initial-value problem clearly
Start with a first-order equation written as y' = f(x, y). In the expression field, enter only the right-hand side, using x and y as the independent and dependent variables. For example, if y' = x + y, enter x + y. The parser supports ordinary arithmetic, parentheses, powers written with ^, the constants pi and e, and common functions such as sin, cos, exp, log, and sqrt. Then provide the known point (x, y) and the step size h. A positive h advances to the right, while a negative h performs the same RK4 construction backward. The step size cannot be zero because that would not advance the solution. All numeric inputs and every function value must remain finite. Multiplication must be explicit, so write 2*x rather than 2x. This precise input format prevents an equation label or implicit multiplication from being interpreted in an unintended way and keeps the four evaluations reproducible.
Follow the four slope estimates
The calculator reports k1 through k4 as slopes, following the convention k1 = f(x, y), rather than as increments already multiplied by h. First, k1 uses the initial point. The second estimate uses the midpoint x + h/2 and predicts its y-coordinate with h*k1/2. The third estimate stays at the midpoint but replaces that prediction with h*k2/2, which corrects the direction using the second slope. Finally, k4 evaluates the derivative at x + h with a full-step y prediction based on k3. The returned k2_point, k3_point, and k4_point fields expose those evaluation coordinates directly. This matters because textbooks sometimes use the same k symbols for h times each slope. If your source follows that alternative convention, multiply each reported k value by h before comparing individual stages. The final y approximation is unchanged when the corresponding formula is used consistently.
Interpret the weighted update and its limits
RK4 combines the slopes as (k1 + 2*k2 + 2*k3 + k4)/6, giving the two midpoint estimates twice the weight of the endpoint estimates. The calculator returns this quantity as weighted_slope, then computes y_next = y + h*weighted_slope and x_next = x + h. One RK4 step is fourth-order accurate in the standard local sense for a sufficiently smooth derivative, but that statement is not a guarantee that any chosen step size is small enough. A rapidly changing, singular, discontinuous, or stiff problem may require a much smaller h or a method with error control. This tool deliberately performs exactly one fixed step; it does not estimate truncation error, adapt the step size, or solve across an interval. To assess sensitivity, compare one step of size h with two successive steps of size h/2 in a full solver. Use the displayed stages to locate differences caused by expression entry, rounding, or slope convention.
What you can do with it
Check a textbook exercise
Verify every intermediate RK4 slope and the next y approximation instead of comparing only a final number.
Debug a numerical solver
Compare one known step, including its midpoint states, with an implementation in a spreadsheet, script, or simulation.
Document an engineering calculation
Record the four deterministic derivative evaluations and weighted update used to advance a model by one step.
FAQ
What does one calculation cost through the API?
One API request costs $0.002. The browser calculator runs locally and is free to use.
Are k1, k2, k3, and k4 slopes or increments?
They are slopes: direct values of f(x, y). Multiply each by h if your reference defines each k as an increment.
Can the step size be negative?
Yes. A finite negative step size applies the same RK4 formulas to advance toward a smaller x value.
Which expression syntax is supported?
Use x, y, numbers, pi, e, parentheses, +, -, *, /, ^, and supported single-argument functions such as sin, cos, exp, log, and sqrt.
Does this solve the differential equation over an interval?
No. It performs exactly one fixed RK4 step from the supplied initial point and does not choose a step size or estimate error.
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/calculus/rk4-single-step \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"expression":"x + y","x":0,"y":1,"step_size":0.1}'const res = await fetch("https://api.kit.forhosting.com/calculus/rk4-single-step", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"expression": "x + y",
"x": 0,
"y": 1,
"step_size": 0.1
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/calculus/rk4-single-step",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"expression": "x + y",
"x": 0,
"y": 1,
"step_size": 0.1
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/calculus/rk4-single-step", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"expression":"x + y","x":0,"y":1,"step_size":0.1}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"expression":"x + y","x":0,"y":1,"step_size":0.1}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/calculus/rk4-single-step", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"expression": "x + y",
"x": 0,
"y": 1,
"step_size": 0.1
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "calculus.rk4_single_step",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_chars | 500 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |