Runge-Kutta Method (2nd Order, 1st-Order ODE)
Solve dy/dx = f(x, y) numerically with the 2nd-order Runge-Kutta (midpoint) method, showing the approximate value at the end point, a table of the numerical solution, and a solution-curve graph.
Input
Example equations (tap to fill in)
Operators: + - * / ^ (power). Functions: sin cos tan asin acos atan sinh cosh tanh exp log (natural log) ln log10 sqrt cbrt abs pow(a,b). Constants: pi (π), e. Variables: x and y. The equation is integrated from x0 to the end point x using step size h.
Result
When dy/dx = x - y, y(0) = 1
Approximate solution y at end point x = 3
2.100112
Steps
30
Number of subintervals
Effective step size h
0.1
Adjusted to fit the end point
Initial condition
y(0) = 1
End point x = 3
Numerical solution (x, y)
| Step | x | y | Slope f(x, y) |
|---|---|---|---|
| 0 | 0 | 1 | -1 |
| 2 | 0.2 | 0.83805 | -0.63805 |
| 3 | 0.3 | 0.782435 | -0.48244 |
| 5 | 0.5 | 0.714152 | -0.21415 |
| 6 | 0.6 | 0.698807 | -0.09881 |
| 8 | 0.8 | 0.699951 | 0.10005 |
| 9 | 0.9 | 0.714455 | 0.18554 |
| 11 | 1.1 | 0.767059 | 0.33294 |
| 12 | 1.2 | 0.803689 | 0.39631 |
| 14 | 1.4 | 0.894436 | 0.50556 |
| 15 | 1.5 | 0.947465 | 0.55254 |
| 17 | 1.7 | 1.066485 | 0.63352 |
| 18 | 1.8 | 1.131669 | 0.66833 |
| 20 | 2 | 1.271645 | 0.72836 |
| 21 | 2.1 | 1.345839 | 0.75416 |
| 23 | 2.3 | 1.501348 | 0.79865 |
| 24 | 2.4 | 1.58222 | 0.81778 |
| 26 | 2.6 | 1.749243 | 0.85076 |
| 27 | 2.7 | 1.835065 | 0.86494 |
| 29 | 2.9 | 2.010621 | 0.88938 |
| 30 | 3 | 2.100112 | 0.89989 |
How it works
- Enter an expression for the right-hand side f(x, y), specify the initial values x0 and y0, the step size h, and the end point x, and the equation is solved numerically from x0 to the end point x with the 2nd-order Runge-Kutta method.
- At each step the slope k1 = f(x, y) and the midpoint slope k2 = f(x + h/2, y + h/2·k1) are computed, then y is updated as y_{n+1} = y_n + h·k2 (midpoint method, 2nd-order accuracy).
- A smaller step size h gives higher accuracy but increases the number of steps. The value of h is adjusted automatically to fit the end point so the step count is an integer.
- Expressions may use the variables x and y, the four arithmetic operations and ^ (power), functions such as sin, cos, exp, log, sqrt, and abs, and the constants pi and e.
- For equations whose solution grows or decays sharply the value may diverge. In that case, use a smaller step size or narrow the range to the end point.
- The result shows the approximate solution at the end point in a large display, along with a table of (x, y) and the slope at each step and a graph of the solution curve.
Related calculators
Function Graph Plotter f(x)
NumericalType an expression such as sin(x) or x^2-2 and instantly plot its graph over a chosen x range. Maximum, minimum, zeros, and sample point values are shown alongside.
Open calculator →Graph Two Functions f(x) and g(x)
NumericalPlot two expressions f(x) and g(x) on the same axes in distinct colors, and automatically find their max, min, and intersection points.
Open calculator →Data Point f(x) Graph Plotter
NumericalJust paste your (x, y) data points to instantly draw a line-and-point chart. See the point count plus the minimum, maximum, and average of y at the same time.
Open calculator →Plot Data Points f(x), g(x)
NumericalPaste two sets of (x, y) data points and get f(x) and g(x) drawn as color-coded overlaid line graphs, with each series' point count and min/max.
Open calculator →