keisoku

Runge-Kutta Method (2nd Order, Second-Order ODE)

Convert y''=f(x,y,y') into a first-order system and solve it numerically with the 2nd-order Runge-Kutta method. Get y and y' at the end point, plus a solution curve and a table of every step.

Input

y''=

Example equations (tap to insert)

Simple harmonic y''=-y
Damped oscillation y''=-y-0.2v
Forced oscillation
y''=-9.8 (free fall)
van der Pol

Variables are x (independent), y (solution), and v (= y', the slope). Operators: + - * / ^ (power). Functions: sin cos tan exp log (natural log) ln log10 sqrt abs pow(a,b), etc. Constants: pi (π), e.

Result

Approximate solution y at x = 10

y ≒ -0.333058

Slope there y' ≒ 0.189841

-1-0.500.51012345678910x-axis / y-axis

Steps

100 steps

Step size h = 0.1

Initial conditions

y(0) = 1

y'(0) = 0

Solution at end point

y = -0.3331

y' = 0.1898


Solution trace (excerpt)

xyy' (= v)
010
0.80.711093-0.663591
1.7-0.019739-0.840923
2.5-0.572066-0.47327
3.3-0.720850.105891
4.2-0.3866920.570002
50.1032750.58628
5.80.4624880.270557
6.70.490978-0.197022
7.50.218389-0.439761
8.3-0.136527-0.399268
9.2-0.374116-0.101006
10-0.3330580.189841

y' = -y - 0.2*v is rewritten as the system y' = v, v' = f(x, y, v) and integrated step by step with the 2nd-order Runge-Kutta method.

How it works

  • A second-order equation y''=f(x,y,y') is solved by tracking the solution y and its slope y' (written as v) together as a first-order system. The expression may use three variables: the independent variable x, the solution y, and the slope v (=y').
  • Enter the right-hand side, the initial point x0, the initial value y(x0), the initial slope y'(x0), the step size h, and the end point x_end, and the approximate y and y' at the end point are shown prominently.
  • Smaller step sizes h give higher accuracy but increase the number of steps and the computation cost. If the result oscillates or diverges, try reducing h first.
  • You can include functions such as sin, cos, exp, log, and sqrt, as well as constants like pi (the circle constant) and e (the base of the natural logarithm). The two-argument pow(a,b) is also supported.
  • Quickly check the behavior of equations of motion that appear often in physics, such as simple harmonic motion y''=-y, damped oscillation y''=-y-0.2y', and forced oscillation with an external force.
  • The displayed table is a thinned-out excerpt of the computation steps, and the solution-curve graph also marks the positions of the initial point and the end point.