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
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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
- Some Tricks to solve problems on Impartial games
- Solve the Linear Equation of Single Variable
- Mathematics | System of Linear Equations
- Find n-variables from n sum equations with one missing
- Pair of integers (a, b) which satisfy the given equations
- Number of solutions to Modular Equations
- Mathematics | L U Decomposition of a System of Linear Equations
- Find 'N' number of solutions with the given inequality equations
- Data Science - Solving Linear Equations
- Find if two given Quadratic equations have common roots or not
- Data Science | Solving Linear Equations
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