4th order Runge Kutta method for 2nd order ODE

Click For Summary

Discussion Overview

The discussion revolves around the application of the 4th order Runge-Kutta (RK4) method for solving second-order ordinary differential equations (ODEs). Participants explore the conversion of a second-order ODE into a system of first-order ODEs and the subsequent numerical integration steps involved in the RK4 method.

Discussion Character

  • Exploratory
  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant expresses confusion about applying the RK4 method to a second-order ODE and seeks clarification on the numerical integration steps.
  • Another participant suggests that the first step is to separate the second-order equation into two first-order equations and apply the RK4 method to the second equation to find acceleration.
  • There is a discussion about whether to include the step size \( h \) in the intermediate calculations (k-values and l-values) or only in the final update equations.
  • Some participants propose that all RK terms should include the step size \( h \) early in the calculations rather than at the end.
  • A later post provides a specific example of applying the RK4 method to a second-order ODE, detailing the calculations for each step and questioning the treatment of terms involving zero coefficients.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to include the step size \( h \) in the RK4 calculations, leading to differing opinions on the correct formulation of the method. The discussion remains unresolved regarding the optimal way to apply the RK4 method to the second-order ODE.

Contextual Notes

Participants express uncertainty about the proper handling of the step size \( h \) in the RK4 algorithm and its implications for the accuracy of the numerical solution. There are also unresolved questions about the treatment of terms in the equations when coefficients are zero.

Cypeq
Messages
5
Reaction score
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
<br /> x&#039;&#039;(t) = Ax&#039;(t) + Bx(t) + C<br />
i know that step i need to take is to make some assignments
x(t) = x_1
x&#039;(t) = x_2
which allows me to deal with two 1st order ODE
x&#039;(t) = x_2
x&#039;&#039;(t) = A x_2 + B x_1 + C
but I'm confused how exact runge kutta steps will look like
that's my idea totally not shure if correct:
k_1 = x_{2,n}
l_1 = f(t, x_{1,n}, x_{2,n}) = A x_{2,n} + B x_{1,n} + C

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

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

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

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

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_
k_2 =x_{2,n} + \frac 1 2 k_1
and so on... ending with
k_4 =x_{2,n} + k_3
l_4 = f(t + h, x_{1,n} + k_3, x_{2,n} + l_3)

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
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:
 
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 acceleration*step_size) out in your equation for x_prime -- maybe that is the problem?

Then repeat, over and over and over.
 
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 h 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:
k_2 =( x_{2,n} + \frac 1 2 l) h
but than i woudn't add h in x1,n+1 = ... part
 
Last edited:
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+\Deltat/2, x+\Deltax/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.
 
Cypeq said:
k_2 =( x_{2,n} + \frac 1 2 l) h

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.
 
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" ?
 

Similar threads

  • · Replies 65 ·
3
Replies
65
Views
9K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 0 ·
Replies
0
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K