Given following inputs,
- An ordinary differential equation that defines value of dy/dx in the form x and y.
- Initial value of y, i.e., y(0)
Thus we are given below.
The task is to find value of unknown function y at a given point x.
The Runge-Kutta method finds approximate value of y for a given x. Only first order ordinary differential equations can be solved by using the Runge Kutta 4th order method.
Below is the formula used to compute next value yn+1 from previous value yn. The value of n are 0, 1, 2, 3, ….(x – x0)/h. Here h is step height and xn+1 = x0 + h
. Lower step size means more accuracy.
The formula basically computes next value yn+1 using current yn plus weighted average of four increments.
- k1 is the increment based on the slope at the beginning of the interval, using y
- k2 is the increment based on the slope at the midpoint of the interval, using y + hk1/2.
- k3 is again the increment based on the slope at the midpoint, using using y + hk2/2.
- k4 is the increment based on the slope at the end of the interval, using y + hk3.
The method is a fourth-order method, meaning that the local truncation error is on the order of O(h5), while the total accumulated error is order O(h4).
Below is implementation for the above formula.
The value of y at x is : 1.103639
Time Complexity of above solution is O(n) where n is (x-x0)/h.
Some useful resources for detailed examples and more explanation.
This article is contributed by Arpit Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Write an Efficient Method to Check if a Number is Multiple of 3
- Babylonian method for square root
- Print all permutations in sorted (lexicographic) order
- Horner's Method for Polynomial Evaluation
- Find number of solutions of a linear equation of n variables
- Multiplicative order
- Primality Test | Set 1 (Introduction and School Method)
- Primality Test | Set 2 (Fermat Method)
- Gaussian Elimination to Solve Linear Equations
- Program for Bisection Method
- Program for Newton Raphson Method
- Program to find the Roots of Quadratic equation
- Number of sextuplets (or six values) that satisfy an equation
- Largest number smaller than or equal to n and digits in non-decreasing order
- Tidy Number (Digits in non-decreasing Order)