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 firstname.lastname@example.org. 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
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 2nd order method to solve Differential equations
- Euler Method for solving differential equation
- Predictor-Corrector or Modified-Euler method for solving Differential equation
- Solve the Linear Equation of Single Variable
- Gaussian Elimination to Solve Linear Equations
- Some Tricks to solve problems on Impartial games
- Find number of solutions of a linear equation of n variables
- Number of sextuplets (or six values) that satisfy an equation
- Sort an array after applying the given equation
- Number of integral solutions of the equation x1 + x2 +.... + xN = k
- Smallest root of the equation x^2 + s(x)*x - n = 0, where s(x) is the sum of digits of root x.
- Number of non-negative integral solutions of sum equation
- Number of integral solutions for equation x = b*(sumofdigits(x)^a)+c
- Program to find number of solutions in Quadratic Equation
- Find the missing value from the given equation a + b = c
- Absolute difference between sum and product of roots of a quartic equation
- Number of solutions for the equation x + y + z <= n
- Print values of 'a' in equation (a+b) <= n and a+b is divisible by x
- Equation of circle from centre and radius