Runge Kutta 4: problems in application in computer simulation

Click For Summary
SUMMARY

The discussion focuses on implementing the Runge-Kutta 4 (RK4) method for a 3D physics simulator, specifically for calculating kinematics involving velocity and acceleration. The user is transitioning from an Euler integrator to RK4 but is struggling with the application of the RK4 equations, particularly in interpreting the k_2 and k_3 terms. Key equations discussed include the relationships between velocity, acceleration, and force, with specific emphasis on how to compute these using RK4 in C#. The conversation highlights the need for clarity on how to handle vector calculations within the RK4 framework.

PREREQUISITES
  • Understanding of Ordinary Differential Equations (ODEs)
  • Familiarity with the Runge-Kutta 4 method
  • Proficiency in C# programming
  • Knowledge of vector mathematics and kinematics
NEXT STEPS
  • Study the implementation of Runge-Kutta methods in C#
  • Learn about vector calculus in the context of physics simulations
  • Explore examples of RK4 applied to kinematic equations
  • Investigate the use of quaternions for 3D rotations in simulations
USEFUL FOR

Physics simulation developers, game developers, and anyone interested in numerical methods for solving differential equations in programming environments.

asmatic
Messages
2
Reaction score
0
Hi everyone!

Despite I have not too much knowledge of ODE's I'm trying to implement a more or less general 3D physics simulator.

By now, the simulator (only kinematics and simple rotations of a body rigid, at the moment) works with euler integrator but I'd like to move to some more advanced integrators, like Runge-Kutta 4 (RK4)
The problem is at the moment of applying the teorethical equations to the code:

for example to the simplest kinematics equations:

[tex]\vec{v_n_+_1} = \vec{v_n} + \vec{a} \Delta t[/tex]
[tex]\vec{s_n_+_1} = \vec{s_n} + \vec{v} \Delta t[/tex]
[tex]\vec{a} = \frac {\vec{F}} {m}[/tex]
and
[tex]\vec{a} = \frac {d \vec{v}}{dt}[/tex]
[tex]\vec{v} = \frac {d \vec{s}}{dt}[/tex]

ok, the RK4 says that
[tex]y(x+\Delta x) = y(x) + \frac{1}{6} (k_1 + 2k_2 + 2k_3 + k4)[/tex]
where
[tex]k_1 = (\Delta x) y'(x,y)[/tex]
[tex]k_2 = (\Delta x) y'(x + \frac {\Delta x}{2}, y + \frac {k_1}{2})[/tex]
[tex]k_3 = (\Delta x) y'(x + \frac {\Delta x}{2}, y + \frac {k_3}{2})[/tex]
[tex]k_4 = (\Delta x) y'(x + \Delta x,y + k_3)[/tex]
(x is time, and y is the function speed for example and later y is space)

I have searched for the web and in some articles but I' can't find any example appliet to this equations.
Also I'm working with 3d vectors (and quaternions in the future) and I don't know i this may represent a problem at the moment of using the integrator
I think that [itex]k_1[/itex] must have the form (changing x for time and y for speed)
[tex]k_1 = (\Delta t) y'(t,\vec{v}) = \Delta t \frac{d\vec{v}}{dt} = \Delta t \cdot \vec{a}[/tex]
a is a vetor that can be easily calculated from the net force applied and the mass.
So I can translate k1 easily into C# code

However, I'm confused with [itex]k_2[/itex] I'm suposed to convert this
[tex]k_2 = (\Delta t) y'(t + \frac {\Delta t}{2}, \vec{v} + \frac {k_1}{2})[/tex]
into this?
[tex]k_2 = (\Delta t) \frac{d(\vec{v}+\frac{k_1}{2})}{d(t+\frac{\Delta t}{2})}[/tex] :confused:

any clue in how to interpret the k2, and k3 terms will be very much appreciated

regards
 
Physics news on Phys.org
It appears that you wish to compute the velocity and displacement of something that has mass m and is acted on by a force given by some function of velocity (v(t)) and time (t)

So F(v(t),t) = ma

This means your acceleration is also a function of velocity and time

a(v(t),t) = F(v(t),t)/m

You could even have a variable mass in that expression, will not change the RK4 computations.

You have

[tex]\frac {dv(t)} {dt} = a(x,t)[/tex]

we need and initial condition (v(0))

Now apply the RK4 formulas

[tex]v(t + \Delta t) = v(t) + \frac {k_1 + 2k_2 +2k_3 + k_4} 6[/tex]

[tex]k_1 = \Delta t a(v(t),t)[/tex]

[tex]k_2 =\Delta t a (v(t) + \frac {k_1} 2 , t + \frac {\Delta t} 2 )[/tex]

[tex]k_3 = \Delta t a (v(t) + \frac {k_2} 2 , t + \frac {\Delta t} 2 )[/tex]

[tex]k_4 =\Delta t a (v(t) + k_3 , t + \Delta t )[/tex]

To get the position you will need to do a similar computation for

[tex]v(s,t) = \frac {d s} {d t}[/tex]

Initially need to understand how I applied RK4. Your are not doing it right.
 
thanks for your reply Integral.

I'm still a little lost

at each step of integration I compute the total force applied the the center of mass and so, calculing the acceleration which is a vector.

with acceleration, I compute velocity, and position, that are too vectors.

So if acceleration is a vector and not a function of velocity and time,
how can I calculate things like
[tex]k_2 =\Delta t a (v(t) + \frac {k_1} 2 , t + \frac {\Delta t} 2 )[/tex]

? :confused:

regards
 

Similar threads

  • · Replies 65 ·
3
Replies
65
Views
10K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 14 ·
Replies
14
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K