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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Sum of elements in 1st array such that number of elements less than or equal to them in 2nd array is maximum
- Program to find root of an equations using secant method
- Solve the Linear Equation of Single Variable
- Some Tricks to solve problems on Impartial games
- Linear Diophantine Equations
- Mathematics | L U Decomposition of a System of Linear Equations
- Mathematics | System of Linear Equations
- Using Chinese Remainder Theorem to Combine Modular equations
- Number of solutions to Modular Equations
- Find n-variables from n sum equations with one missing
- System of Linear Equations in three variables using Cramer's Rule
- Find 'N' number of solutions with the given inequality equations
- Find the repeating and the missing number using two equations
- Find the values of X and Y in the Given 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 email@example.com. 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