Runge-Kutta 4th order method (RK4) for second order Diff Eq

In summary, the person is trying to use RK4 to solve a first order differential equation. They are having trouble getting started because they do not understand the equations. They try to solve the higher ordered equation first, but it is coupled so they think it is wrong. They then solve for x and get an incorrect result. They figure out how to solve both equations at the same time and are able to advance one time step using the intermediate solutions.
  • #1
Helmholtz
19
0

Homework Statement



Hello, maybe this is due to my lack of understand of RK4, but I have an equation: x'' + b^2*x=0 (derivatives with respect to variable t) and I need to use RK4 to find the solution on an interval. I can readily find solutions analytically, but my understanding of RK4 is that I need the problem in a first order diff eq, which I do not accomplish when I use characteristic equations. Initial conditions are x(t)=0 and x'(0)=0. The intervals is 0 to 4[itex]\pi[/itex] and step sizes of h.

Homework Equations


Find diff eq, such that y'=f(t,y)

RK4 equations:
yn+1= yn + h/6*(k1 + 2*k2 + 2*k3 + k4)

k1=f(tn,yn)

k2=f(tn+h/2,yn+k1*h/2)

k3=f(tn+h/2,yn+k2*h/2)

k4=f(tn+h,yn+k3*h)


The Attempt at a Solution



My attempt to break the problem to first order is a substitution with x'=v

And it follows that that: v'= -b^2*x = f(t,x).

Now I have two first order differential equations. I can use RK4 to get values for v and x, but it seems like my values of v depend on x and vice verse? Here is what I have so far, but it is coupled so I think it's wrong.

First I solved for the higher ordered one, aka v. So:

vn+1 = vn + 1/6*(l1 + 2*l2 + 2*l3 +l4).

Where:

l1= -b^2*xn*h
l2= -b^2*xn*h*(1+h/2)
l3= -b^2*xn*h*(1+h/2+h2/4)
l4= -b^2*xn*h*(1+h/2+h2/2+h3/4)

Now I solved for x with the following:

xn+1 = xn + 1/6*(k1 + 2*k2 + 2*k3 + k4)

Where:
k1= vn*h
k2= vn*h*(1+h/2)
k3= vn*h*(1+h/2+h2/4)
k4= vn*h*(1+h/2+h2/2+h3/4)

Is this right? Since I have initial conditions I think I can build this up to the full solution since I know v0 and x0.
 
Last edited:
Physics news on Phys.org
  • #2
Sorry to say, but you got it all wrong! The point is to solve both equations at the same time, and use the intermediate solutions to get a better guess for the next intermediate solution, and when you have all 4 of them you take an "average" to actually advance one time step.

Check this thread for more details:
https://www.physicsforums.com/showthread.php?t=671526
 
  • #3
I have figured it out, thanks DrClaude.
 
Last edited:

1. What is the Runge-Kutta 4th order method (RK4) for second order differential equations?

The Runge-Kutta 4th order method, also known as RK4, is a numerical technique used to solve second order differential equations. It is a popular method because it is relatively simple to implement and offers a good balance between accuracy and computational efficiency.

2. How does RK4 work?

RK4 works by breaking the differential equation into smaller steps and using a weighted average of the derivative at each step to approximate the solution. This is done by evaluating the derivative at four different points within each step and taking a weighted average of these values.

3. What types of second order differential equations can RK4 solve?

RK4 can be used to solve any second order differential equation that can be written in the form y'' = f(x,y,y'). This includes both ordinary and partial differential equations with initial or boundary conditions.

4. What are the advantages and disadvantages of using RK4?

The main advantage of RK4 is that it is a relatively simple and efficient method for solving second order differential equations. It also has a higher accuracy compared to lower order methods. However, it can be computationally expensive for very small step sizes and may not be suitable for stiff differential equations.

5. How do I implement RK4 for a specific differential equation?

Implementing RK4 involves breaking down the differential equation into smaller steps and using a computer program or algorithm to calculate the solution. There are many online resources and textbooks available that provide step-by-step instructions on how to implement RK4 for different types of differential equations. It is also important to choose an appropriate step size and ensure the initial conditions are properly defined.

Similar threads

  • Programming and Computer Science
2
Replies
36
Views
3K
  • Calculus and Beyond Homework Help
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
14
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
Replies
56
Views
673
  • Calculus and Beyond Homework Help
Replies
6
Views
50K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Calculus and Beyond Homework Help
Replies
12
Views
2K
  • Calculus and Beyond Homework Help
Replies
6
Views
2K
  • Calculus and Beyond Homework Help
Replies
3
Views
2K
Back
Top