Given the following inputs:
- An ordinary differential equation that defines the value of dy/dx in the form x and y.
- Initial value of y, i.e., y(0).
The task is to find the value of unknown function y at a given point x, i.e. y(x).
Input: x0 = 0, y0 = 1, x = 2, h = 0.2
Output: y(x) = 0.645590
Input: x0 = 2, y0 = 1, x = 4, h = 0.4;
Output: y(x) = 4.122991
The Runge-Kutta method finds an approximate value of y for a given x. Only first-order ordinary differential equations can be solved by using the Runge Kutta 2nd order method.
Below is the formula used to compute next value yn+1 from previous value yn.
yn+1 = value of y at (x = n + 1) yn = value of y at (x = n) where 0 ≤ n ≤ (x - x0)/h h is step height xn+1 = x0 + h
The essential formula to compute the value of y(n+1):
The formula basically computes the next value yn+1 using current yn plus the weighted average of two 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 + h*K1/2).
The method is a second-order method, meaning that the local truncation error is on the order of O(h3), while the total accumulated error is order O(h4).
Below is the implementation of the above approach:
y(x) = 0.645590
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
- Gill's 4th Order Method to solve Differential Equations
- Runge-Kutta 4th Order Method to Solve Differential Equation
- Second Order Linear Differential Equations
- Gaussian Elimination to Solve Linear Equations
- Euler Method for solving differential equation
- Predictor-Corrector or Modified-Euler method for solving Differential equation
- Program to find root of an equations using secant method
- Find the values of X and Y in the Given Equations
- Linear Diophantine Equations
- Solve the Linear Equation of Single Variable
- Some Tricks to solve problems on Impartial games
- Pair of integers (a, b) which satisfy the given equations
- Mathematics | System of Linear Equations
- Number of solutions to Modular Equations
- Find n-variables from n sum equations with one missing
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Yash_R