4th order Runge Kutta method for 2nd order ODE

In summary, you have a problem understanding how to use RK4 to solve 2nd order ODEs, and you are confused about how exact runge-kutta steps will look. Your proffesor told you to make some assignments, and then use Runge-Kutta to solve two 1st order ODEs. You are also confused about how numerical integration looks for the first element of the velocity equation.
  • #1
Cypeq
5
0
Hello,
i have a bit of a problem with uderestanding how exactly we use RK4 method for solving 2nd order ODE.
And last conversation with my proffesor only added up to my confiusion.
Further more i couldn't find any example dealing with this problem if any1 could provide link explaining
this problem along with solving example that would be very helpfull.

so let's consider very basic 2nd order ODE
[tex]
x''(t) = Ax'(t) + Bx(t) + C
[/tex]
i know that step i need to take is to make some assignments
[tex]x(t) = x_1[/tex]
[tex]x'(t) = x_2[/tex]
which allows me to deal with two 1st order ODE
[tex]x'(t) = x_2[/tex]
[tex]x''(t) = A x_2 + B x_1 + C[/tex]
but I'm confused how exact runge kutta steps will look like
that's my idea totaly not shure if correct:
[tex]k_1 = x_{2,n}[/tex]
[tex]l_1 = f(t, x_{1,n}, x_{2,n}) = A x_{2,n} + B x_{1,n} + C[/tex]

[tex]k_2 =x_{2,n} + \frac 1 2 l_1[/tex]
[tex]l_2 = f(t + \frac 1 2 h, x_{1,n} + \frac 1 2 k_1, x_{2,n} + \frac 1 2 l_1)[/tex]

[tex]k_3 =x_{2,n} + \frac 1 2 l_2[/tex]
[tex]l_3 = f(t + \frac 1 2 h, x_{1,n} + \frac 1 2 k_2, x_{2,n} + \frac 1 2 l_2)[/tex]

[tex]k_4 =x_{2,n} + l_3[/tex]
[tex]l_4 = f(t + h, x_{1,n} + k_3, x_{2,n} + l_3)[/tex]

[tex]x_{1,n+1} = x_{1,n} + \frac 1 6 h(k_1 + 2k_2 + 2k_3 + k_4)[/tex]
[tex]x_{2,n+1} = x_{2,n} + \frac 1 6 h(l_1 + 2l_2 + 2l_3 + l_4)[/tex]

I'm preticiulary interested how numerical integration looks like for first element x'(t) = x_2

Proffesors idea was that it should be in all K_1 = , K_2 = ... there should be L_ instead of K_
[tex]k_2 =x_{2,n} + \frac 1 2 k_1[/tex]
and so on... ending with
[tex]k_4 =x_{2,n} + k_3[/tex]
[tex]l_4 = f(t + h, x_{1,n} + k_3, x_{2,n} + l_3)[/tex]

Please help me and correct possible errors... Help me Physics Forum you are my only hope ;-)

edit: since few hours passed with above 70 views
some1 knowing the solution but maybe not having a time write it down just say if it's good or bad please.
 
Last edited:
Physics news on Phys.org
  • #2
Hello Cypeq,
I don't get what u mean by "x2,n"
But..what u say seems correct(I too just recently fell into this stuff)

The thing "I think" u r looking for .. I try to tell my way as follows..
once u get the two 1st order ODE's...assign increment step with a variable
like k with x1, l with x2
if ur ODE involves both x1,x2 it'll be x1+k(or k/2) llly x2 + l ,etc
Then calc successive coefficients...

I hope that was helpful...
sorry if it was irrelevant...:confused:
 
  • #3
I'm having a little trouble reading understanding the confusion, so sorry if I miss the mark.

You should first separate the 2nd order equation into 2 equations, just like you have done. Then you apply your solution technique (in this case Runge-Kutta) to the highest order one (your second one), and solve for it (basically get the "acceleration"). Now use its value to solve the first one (your "velocity").

Your velocity should be equal to its original value plus acceleration*step_size. Actually, I think you are leaving that (the accleration*step_size) out in your equation for x_prime -- maybe that is the problem?

Then repeat, over and over and over.
 
  • #4
Thx for your answers

@nanuath: x2,n is ofcourse value of x2 at n-th step meaning current velocity.
if i made some confusion by my writing ki are solving value of x(t) = x1 which can be seen as possition
and the li are solving first derrivative of possition x'(t) = x2 which can be seen as velocity.
A, B, C are constant coefficients their value is meaningless here.@diggy: the confusion is about the way my prof. said the k1... k4 values should be obtained.
i'm still not 100% if I'm aplying runge kutta here the right way if so tell me :P.

I left the multiplication by step size [tex] h [/tex] to the end of equation where i get weighted results after all steps.
I'm not shure if it changes anything.. I think you should add it (h) in final equation or in all four steps of algorythm.
For example with added step size imo k2 would look like:
[tex]k_2 =( x_{2,n} + \frac 1 2 l) h [/tex]
but than i woudn't add h in x1,n+1 = ... part
 
Last edited:
  • #5
The only reason I wouldn't factor out the h early, is that you are using the h to determine where the other guesses (k2, k3,k4 )come from (they should all be ~h away). If you are making giant steps (without using h) for your estimates then they won't make any sense.

Think of the steps as t+[tex]\Delta[/tex]t/2, x+[tex]\Delta[/tex]x/2 in the RK estimates.

Otherwise I think your ordering looks right, i.e. get each RK estimate 1, get each RK estimate 2, ... step both values up using 4 estimates, start over.
 
  • #6
Cypeq said:
[tex]k_2 =( x_{2,n} + \frac 1 2 l) h [/tex]

Read over your post again, and yes, every RK term should have the h in there like you do above, not at the end like you have in the original post.

Edited: And yes, then you don't need another h in the n+1=n part. They are already included.
 
  • #7
Not so sure whether will there be anyone paying attention to this post as it's been for quite some time. But anyway here goes, hopefully I am able to get some assistance from PF.

Apparently I came across the following steps which is the solution for the initial question in the post,

x" = dv/dt = 10 - 4x - v = f(t, x, v)
x'= dx/dt = v = g(t, x, v)
subject to initial conditions x(0) = 1, x'(0) = 0
Using a time step of h = 1 second

We start with t = 0, x = 1, v = 0
kf is the step for v while kg is the step for x
kf1 = f(t, x, v) = f(0, 1, 0) = 6
kg1 = g(t,x,v) = g(0, 1, 0) = 0

kf2 = f(t+h/2, x+kg1*h/2, v+kf1*h/2)
= f(0.5, 1, 3) = 3
kg2 = g(t+h/2, x+kg1*h/2, v+kf1*h/2)
= g(0.5, 1, 3) = 3

kf3 = f(t+h/2, x+kg2*h/2, v+kf2*h/2)
= f(0.5, 2.5, 1.5) = -1.5
kg3 = g(t+h/2, x+kg2*h/2, v+kf2*h/2)
= g(0.5, 2.5, 1.5) = 1.5

kf4 = f(t+h, x+kg3*h, v+kf3*h)
= f(1, 2.5, -1.5) = 1.5
kg4 = g(t+h, x+kg3*h, v+kf3*h)
= g(1, 2.5, -1.5) = -1.5

At the next time value, t = 1
x(1) = x(0) + h/6 * (kg1 + 2kg2 + 2kg3 + kg4)
= 2.25
x'(1) = y(0) + h/6 * (kf1 + 2kf2 + 2kf3 + kf4)
= 1.75I have a question, that is if my equation is to be;
x" = dv/dt = 10 - 4x - 0v

would all my values in kg1, kg2, kg3 and kg4 be 0 (zero)? Or, do I only multiply the 0 with x' (velocity or 'v' in the above equation) only when I am calculating for x" ?
 

Related to 4th order Runge Kutta method for 2nd order ODE

1. How does the 4th order Runge Kutta method work for solving 2nd order ODEs?

The 4th order Runge Kutta method is a numerical method used to approximate the solution of a 2nd order ordinary differential equation (ODE). It involves breaking down the ODE into a system of two 1st order ODEs, and then using a series of calculations to estimate the solution at a given point. This method is considered to be more accurate than simpler methods like Euler's method.

2. What are the advantages of using the 4th order Runge Kutta method over other numerical methods?

Compared to other numerical methods, the 4th order Runge Kutta method is more accurate and efficient for solving 2nd order ODEs. It also allows for larger step sizes, which can reduce the overall computation time. Additionally, it is more stable and less prone to errors, making it a reliable method for solving differential equations.

3. Can the 4th order Runge Kutta method be used for solving any type of 2nd order ODE?

Yes, the 4th order Runge Kutta method can be used to solve any type of 2nd order ODE, as long as it can be written in the form of a system of two 1st order ODEs. This includes linear and nonlinear ODEs, as well as initial value and boundary value problems.

4. How do you determine the step size for the 4th order Runge Kutta method?

The step size for the 4th order Runge Kutta method can be determined by considering the desired accuracy of the solution and the stability of the method. Generally, a smaller step size will result in a more accurate solution, but it will also increase the computation time. It is important to balance these factors when selecting the step size for a specific problem.

5. Are there any limitations to using the 4th order Runge Kutta method for solving 2nd order ODEs?

While the 4th order Runge Kutta method is a powerful and versatile method for solving 2nd order ODEs, it does have some limitations. For example, it may not be the most efficient method for solving stiff ODEs, and it may not be suitable for problems with highly oscillatory solutions. In these cases, other numerical methods may be more appropriate.

Similar threads

Replies
61
Views
1K
Replies
14
Views
4K
  • Differential Equations
Replies
6
Views
3K
Replies
7
Views
749
  • Differential Equations
Replies
1
Views
2K
  • Differential Equations
Replies
3
Views
556
  • Differential Equations
Replies
1
Views
1K
  • Quantum Physics
Replies
31
Views
2K
  • Advanced Physics Homework Help
Replies
7
Views
1K
Back
Top