Runge-Kutta Method (RK4, 2nd-Order ODE)
Solve y''=f(x,y,y') numerically with the 4th-order Runge-Kutta method. Enter the initial conditions and step size to get a table of x, y, y' at each step plus a graph of the solution curve.
Input
Examples (tap to fill the RHS and initial conditions)
Variables: x (independent), y (solution), v (=y'; you can also write dy / yp). 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.
Result
Solution y at x = 10
y ≒ -0.839075
Here y' ≈ 0.544014
Steps
100 steps
101 points
Step size h
0.1
Δx = h
Initial conditions
y(0) = 1
y'(0) = 0
Range of y
-0.9997 〜 1
across all steps
Numerical solution (x, y, y')
| Step | x | y | y' (=v) |
|---|---|---|---|
| 0 | 0 | 1 | 0 |
| 7 | 0.7 | 0.764843 | -0.644217 |
| 14 | 1.4 | 0.169968 | -0.985449 |
| 21 | 2.1 | -0.504845 | -0.86321 |
| 29 | 2.9 | -0.970957 | -0.239252 |
| 36 | 3.6 | -0.89676 | 0.442518 |
| 43 | 4.3 | -0.400802 | 0.916164 |
| 50 | 5 | 0.283658 | 0.958925 |
| 57 | 5.7 | 0.83471 | 0.550689 |
| 64 | 6.4 | 0.993185 | -0.116544 |
| 71 | 7.1 | 0.684551 | -0.728965 |
| 79 | 7.9 | -0.045996 | -0.998941 |
| 86 | 8.6 | -0.678714 | -0.734402 |
| 93 | 9.3 | -0.992224 | -0.124462 |
| 100 | 10 | -0.839075 | 0.544014 |
Result of rewriting y' = -y as a system with v = y' and integrating with the 4th-order Runge-Kutta method.
How it works
- Converts the second-order ODE y''=f(x,y,y') into the first-order system y'=v, v'=f(x,y,v) and solves it numerically with the classic 4th-order Runge-Kutta method (RK4).
- Enter the expression for f(x,y,v) (where v denotes the first derivative y'), the initial values x0, y0, y'0 (=v0), the step size h, and the end point xend.
- At each step, four slopes k1 through k4 are computed for both y and v, and a weighted average gives the next values. This is more accurate than second-order methods or Euler's method.
- The endpoint values of y (and y') are shown as the main result, the per-step (x, y, y') values appear in a table, and the solution y is drawn as an SVG graph.
- Smaller step sizes h improve accuracy but require more steps. The expression is parsed with a custom parser that does not use eval.
- Useful for simulating phenomena described by second-order ODEs such as oscillation, damping, and spring motion.
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 →