When ordinary differential equations are hard to solve and one is interested in the effect of initial conditions, the solution of only that particular case is needed. To find this solution one can solve the differential equation in a numerical fashion by numerically integrating the expression.
Consider this simple first order differential equation,
where ' refers to the derivative to x.
The differential equation states what the slope of the solution function is for each x value. This means that in the first approximation we can use this slope to calculate the y value is for a point at x+h, given that we know the position of the previous point y(x), i.e.,
which can be written, by using n as an index for the x positions generated this way as
And we see that by starting with a known values for x and y at n = 0, i.e., x0 and y0, the function can be generated. Note that the step size, h, should theoreticaly be infinitely small for this equation to hold. This approach is called Euler's Method. Methods that introduce smaller errors at the same step-size, h, exist and are therefor preferred in real-life situations. Some of these methods are
Higher order differential equations, of order n can always be expressed as a set of n first order differential equations. This can be appreciated by considering that one can do a successive integrations in order to get numerical results for the lower derivatives, working ones way down to the 0th derivative as being the solution that is sought. Mathematically this is equivalent to introducing n-1 new variables that defined to be successive derivatives of the solution to be found. For example a general third order differential equation
can be rewritten as three first order equations by introducing two new variables, with increasing order of derivatives, so that each next one is the first derivative of the previous one, i.e.,
So that we now have z2(x) = y'' and y''' = z2'(x) and the original equation is reduced from a third first order equation to a first order one.
Together with the two first order equations that defined the z variables, we have three first order equations. This means that expressions for first order numerical integration can be used to solve this set of equations by solving the three equations in reverse order: first solving for z2(x), using a initial value of z2(0), then solving for z1(x), using an initial value of z1(0), and finally solving for y, using an initial value of y0.
One of the more frequently used methods are the Runge-Kutta methods, one example of which is for the second order differential equation:
where '' refers to the second derivative of y to x.
The algorithm is given by [Handbook of Mathematical Functions, Milton Abramowitz and Irene A. Stegun, eds., Dover Publications, Inc., New York, 9th edition, pg. 897, equation 25.5.22)
In these expressions, h the step size of the integration, yn is the y value at point xn, and y'n is the derivative at point xn. The order of the error introduced in yn+1 is h4.
Different Runge Kutta methods are used depending on the order of the error that one is willing to accept, and the form of the differential equation expression itself.