keisoku

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

dy/dx =

Example equations (tap to fill in)

y' = y (exponential growth)
y' = x - y
y' = -2xy
y' = x^2 - y

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

0.60.811.21.41.61.822.200.511.522.53

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)

StepxySlope f(x, y)
001-1
20.20.83805-0.63805
30.30.782435-0.48244
50.50.714152-0.21415
60.60.698807-0.09881
80.80.6999510.10005
90.90.7144550.18554
111.10.7670590.33294
121.20.8036890.39631
141.40.8944360.50556
151.50.9474650.55254
171.71.0664850.63352
181.81.1316690.66833
2021.2716450.72836
212.11.3458390.75416
232.31.5013480.79865
242.41.582220.81778
262.61.7492430.85076
272.71.8350650.86494
292.92.0106210.88938
3032.1001120.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.