Runge-Kutta 2 ODE Solver Calculator
This Runge-Kutta 2 ODE solver calculator approximates an initial-value problem written as y' = f(x,y).
Run — free
Enter the derivative expression, the known point x0 and y0, an endpoint, and a fixed number of steps. You can use the midpoint, Heun, or Ralston second-order formula. The result reports the common step size, both derivative slopes from every step, each weighted increment, and the final approximation, so the numerical process remains transparent and reproducible.
Enter the differential equation and interval
Put only the right-hand side f(x,y) in the equation field. For y' = x + y, enter x + y. The expression supports decimal and scientific-notation numbers, the variables x and y, the constants pi and e, parentheses, addition, subtraction, explicit multiplication, division, powers, and the functions exp, log, sin, cos, and sqrt. Write 2*x rather than 2x, and place function arguments inside parentheses. The initial condition is defined by x0 and y0, meaning that y(x0) equals y0. target_x marks the other end of the interval. It may be above or below x0, so forward and backward integration both work. Finally, choose the exact number of steps. The calculator divides the complete interval into that many equal pieces; it does not interpret the number as a maximum or adjust it while solving. A malformed expression, unsupported name, missing numeric value, or calculation outside the real finite domain produces an input error instead of a partially trustworthy table.
Choose and read an RK2 formula
Every included method is a two-stage, second-order explicit Runge-Kutta formula. First, the solver evaluates k1 = f(x,y) at the current point. It then uses k1 to predict an intermediate location and evaluates k2 there. The midpoint method places that stage halfway through the step and uses k2 as the final slope. Heun's method predicts at the end of the step and averages k1 with k2; it is also called the improved Euler or explicit trapezoid method. Ralston's method places its stage two-thirds through the step and combines one quarter of k1 with three quarters of k2, a choice designed to reduce a common local-error coefficient. The output lists k1, k2, and the resulting increment for each accepted point. Add the increment to the preceding y value to reproduce the displayed next value. Because the stage rules differ, two RK2 variants can return slightly different approximations even though all three have second-order convergence for sufficiently smooth problems.
Assess step size and numerical reliability
The signed step size is (target_x - x0) divided by steps, so increasing the step count reduces the magnitude of every step. For a smooth non-stiff problem, a second-order method generally reduces global error by about a factor of four when the step size is halved, once the calculation is in its asymptotic range. A practical convergence check is therefore to solve with N steps and again with 2N steps, then compare the final y values. Agreement is evidence of stability for that problem, but it is not a rigorous error certificate. Inspect the reported slopes as well: sudden growth, alternating large values, or non-finite arithmetic can indicate that the interval crosses a singularity or that the chosen steps are too coarse. This calculator deliberately uses a fixed count and performs no adaptive error control. It also returns an approximation, not a symbolic solution. Stiff equations, discontinuous derivatives, long integrations, and safety-critical scientific calculations should be checked with an appropriate adaptive solver, domain knowledge, and independent error analysis.
What you can do with it
Verify coursework
Compare the two slopes and weighted increment at every step with a hand-worked RK2 table.
Compare RK2 variants
Run midpoint, Heun, and Ralston formulas on the same initial-value problem and examine their endpoint estimates.
Test convergence
Double the fixed step count and compare final values to judge whether the approximation has stabilized.
FAQ
What does a request cost?
An API request costs $0.002. The same deterministic calculation can also run in the browser.
Which method is used by default?
The midpoint RK2 method is used when method is omitted.
Are Heun and improved Euler the same here?
Yes. The Heun option uses the explicit trapezoid update that averages the slope at the start with a predicted slope at the end.
Can it solve backward from x0?
Yes. Set target_x below x0; the derived step size becomes negative while the requested step count remains positive.
Does it choose the step count automatically?
No. It always uses the positive integer supplied in steps and divides the interval evenly.
Does the result include an error bound?
No. Compare results at increasing step counts or use an adaptive solver when quantified error control is required.
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/rk2-method \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"equation":"x + y","x0":0,"y0":1,"target_x":0.4,"steps":4}'const res = await fetch("https://api.kit.forhosting.com/calculus/rk2-method", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"equation": "x + y",
"x0": 0,
"y0": 1,
"target_x": 0.4,
"steps": 4
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/calculus/rk2-method",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"equation": "x + y",
"x0": 0,
"y0": 1,
"target_x": 0.4,
"steps": 4
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/calculus/rk2-method", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"equation":"x + y","x0":0,"y0":1,"target_x":0.4,"steps":4}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"equation":"x + y","x0":0,"y0":1,"target_x":0.4,"steps":4}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/calculus/rk2-method", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"equation": "x + y",
"x0": 0,
"y0": 1,
"target_x": 0.4,
"steps": 4
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "calculus.rk2_method",
"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_steps | 10000 |
max_expression_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. |