Runge-Kutta: Maintaining Units in Numerical Methods

In summary, when using numerical methods with 4th Order Runge-Kutta, the physical units must be conserved.
  • #1
Roboto
13
1
When conducting numerical methods using 4th Order Runge-Kutta do the physical units have to be maintained?

This never occurred to me until I was writing out all the steps in detail when showing someone I work with the method using a simple projectile motion with drag. It had 4th Order time terms this making the units wrong in the iteration process.

So when using numerical methods, do the units have to be conserved/maintained?
 
Physics news on Phys.org
  • #2
I don't see how any problem can be successfully solved if the units are not preserved. Can you give your example, for clarification with what happened in your situation?
 
  • Like
Likes K Murty
  • #3
Exactly, that was my thoughts. The first sanity check of something is to check the units.

But does that have to be maintained when using numerical methods to solve something as opposed to algebraic.

I will get my document cleaned up and figure out how to post it here. It several pages.
 
  • #4
If it is a missile launch, then I guess you will have derivatives with respect to time. So your steps will be Δt, which should be in the correct unit.
 
  • #5
if we take a simple particle velocity decay in the air, mass*acceleration = K*Velocity2 where K is drag and geometry coefficents of the particle.
If we let u1=position, y, and du1/dt=velocity, and then we let u2=velocity and du2/dt=acceleration

With Runge Kutta,
dy/dt=f(u(t),t)
yn+1=yn+(h/6)*(k1+2*k2+2*k3+k4)
tn+1=tn+h
k1=f(un,t)
k2=f(un+(h/2)*k1,t+h/2)
k3=f(un+(h/2)*k2,t+h/2)
k4=f(un+h*k3,t+h)

for the first equation f(un,t) = u2

Then substituting u2 into the above set of steps we get the time iteration for position as follows:
yn+1=yn+(u2*h/6)*(6+3h+h2+h3/4)

The units of u1 is the same as yn which are meters. The units of u2 is meters/sec. The unit of h is time, seconds

Note the term (u2*h/6) is velocity (m/s) times time (sec) which is distance, meters. So from a units perspective the units are for yn+1, yn, and (u2*h/6) for meters just as one would expect.

But the kicker are the (6+3h+h2+h3/4) terms. The 6 has no units, the 3h has units of time, and h2 has units of time2, and the h3/4 has units of time3. The units in this last group are not preserved.

As you can see, the units are not preserved when applying 4th order Runge -Kutta to numerically solve the ODE

This was a surprise to me in that I thought that the units must be conserved. But the classical method to numerically solve ODE's clearly shows units are not preserved. Hence the question, when using numerical methods, do units have to be conserved?
 
  • #6
How did you get to the yn+1=yn+(u2*h/6)*(6+3h+h2+h3/4) ?
I am just not seeing that jump. I have done a Euler's Method with 2 variables, but not Runge Kutta. I did some search and found this, article, which sets it up as a linear algebra style problem.
https://www.myphysicslab.com/explain/runge-kutta-en.html
There is no combining to get squared or cubed h terms in that.
 
  • #7
if k1=u2
then k2=u2+h/2*k1=u2+h*u2/2
Then k3=u2+h/2*k2=u2+(h/2)*(u2+h*u2/2)=u2+h*u2/2+h2*u2/4
then k4=u2+h*k3=u2+h(u2+h*u2/2+h2*u2/4)=u2+h*u2+h2u2/2+h3u2/4

thus
yn+1=yn+(h/6)*(k1+2k2+2k3+k4) = yn+1=yn+(u2*h/6)*(6+3h+h2+h3/4)

See how this happens? Crazy right? Units are not preserved, and yet this is one of the most popular methods for numerically solving ODE's
 
  • #8
Except that k2 is a function of (un+(h/2)*k1,t+h/2), not equivalent to un+(h/2)*k1, correct?
 
  • #9
In this example, it happens to be that way. The function can have numerous parameters passed to it. In this example, time is not a variable that is being passed.

if we want to get really formal, dy/dt=f(x, dy/dt, dy2/d2t,t). since the original equation was mass*d2y/dt2=K*(dy/dy)2

For Runge Kutta, we convert the 2nd order differential equation into a set of 1st order equations
thus letting u1=y, du1/dt = dy/dt Then we let u2=dy/dt and then du2/dt = d2y/dt2

du1/dt=u2 which is the first function = f1(u2)
du2/dt=(K/mass)(u2)2 which is the second function = f2(u2)

u1,n+1=u1,n+(h/6)*(k11+2k12+2k13+k14)=yn+1

k11, k12, k13, k14 are for evaluating the first function
k21, k22, k23, k24 are for evaluating the second function

Thus this leads back to the previously posted details.
 
  • #10
It is usually smart to put the problem in dimensionless form before doing the Runge-Kutta integration. For example, if you integrate the equations of motion for a missile launch, scale the distances by the radius of the Earth, scale the velocity by the orbital velocity at the surface, scale the time by one unit of v divided by a unit of r. etc. On the other hand, if you are working with the Hydrogen atom, scale the length by the Bohr radius etc, maybe scale the velocity by the velocity of light. It is usually possible to scale the problem so you lose only a little precision with the calculation. You wouldn't want to scale the position vector of a missile relative to the center of the Earth as multiples of the Bohr radius.
 
  • #11
P.S I wrote many Runge Kutta routines without putting the problem in dimensionless terms from the beginning. Sometimes they worked, and sometimes I ran into trouble. After several years (my earlier advise is not obvious) I always put it in dimensionless form first.
 
  • #12
BTW, if you use Latex, your equations will be clearer (and easier to write).
Roboto said:
yn+1=yn+(h/6)*(k1+2*k2+2*k3+k4)

Roboto said:
The units of u1 is the same as yn which are meters. The units of u2 is meters/sec. The unit of h is time, seconds
The equation I quoted requires the units of ##k_n## to be the same as the units of ##y_n / h##, or meters per second. That should make your units work out.
 
  • #13
The k1 through k4 are estimates of y' at point a point then slightly away from that point (see the +h/2 twice then the +h). These different estimates are then weight averaged, to provide a better estimate for y' than the Euler's Method (1st order Runge Kutta). This may explain it for you better than I am - http://lpsa.swarthmore.edu/NumInt/NumIntFourth.html
 
  • #14
Fourth order Runge-Kutta basically uses the Taylor series expansion. The Taylor series expansion should have the right units.

 
Last edited:
  • Like
Likes scottdave
  • #15
Roboto said:
yn+1=yn+(h/6)*(k1+2*k2+2*k3+k4)
is dimensionally correct, so if you substitute correctly, the result should also be correct.
Then substituting u2 into the above set of steps we get the time iteration for position as follows:
yn+1=yn+(u2*h/6)*(6+3h+h2+h3/4)
conversely, this result can not be right.
As you can see, the units are not preserved when applying 4th order Runge -Kutta to numerically solve the ODE
nonsense
This was a surprise to me in that I thought that the units must be conserved. But the classical method to numerically solve ODE's clearly shows units are not preserved. Hence the question, when using numerical methods, do units have to be conserved?
kudos for your gut feelings! units are conserved. anything else means there is an error.but there is something else being overlooked here: your u has two components, one in meters and one in m/s. likewise your f has two components, one in m/s and one in m/s2. idem all k
 
  • Like
Likes scottdave
  • #16
Roboto said:
if we want to get really formal, dy/dt=f(x, dy/dt, dy2/d2t,t). since the original equation was mass*d2y/dt2=K*(dy/dy)2
getting formal means you don’t mix notations and work accurately.
if the original equation is really $$m\ddot y = k\dot y^2$$ then there is no ##x## in the problem and ##\dot y## is a not a function of any of those variables you mention directly, but instead the item you want to find through integration (together with ##y## itself)

and the set of first order equations is $${dy\over dt}=\dot y\\\mathstrut \\ {d\dot y\over dt} ={k\over m}\dot y^2$$
For Runge Kutta, we convert the 2nd order differential equation into a set of 1st order equations
thus letting u1=y, du1/dt = dy/dt Then we let u2=dy/dt and then du2/dt = d2y/dt2

du1/dt=u2 which is the first function = f1(u2)
du2/dt=(K/mass)(u2)2 which is the second function = f2(u2)

u1,n+1=u1,n+(h/6)*(k11+2k12+2k13+k14)=yn+1

k11, k12, k13, k14 are for evaluating the first function
k21, k22, k23, k24 are for evaluating the second function

Thus this leads back to the previously posted details.
looks a lot better than post #1 where ##u## and ##k## only had one index:wink:
and of course you mean ‘follow from evaluating’ instead of ‘are for evaluating’

just to reassure us you now know what to do: please re-write post#1 in an absolutely immaculate form...
 
  • #17
Just to recap, dimensions (or units if you like) should match. You cannot say 3 miles per hour + 2 miles, for example. This is a powerful tool to see if your answer makes sense. This means if you come up with something like you did (6+3h+h2+h3/4) where h carries dimension (time in this case), then they cannot be added as @BvU stated that you did not think it was correct.
You should suspect that something is not right, but don't jump to the conclusion that the Mathematicians, who created the formulas, are wrong. The more likely scenario is that there is a mistake in your workings, somewhere along the line.

Anybody is capable of a mistake. So yes, it is possible that a textbook or test question has an error on it.

Were you able to figure out where your error was, to get the dimensions to match?
 

1. What is the Runge-Kutta method?

The Runge-Kutta method is a numerical algorithm used to solve ordinary differential equations. It is a popular choice for solving differential equations because it is more accurate and efficient than other methods, such as Euler's method.

2. How does the Runge-Kutta method maintain units in numerical methods?

The Runge-Kutta method maintains units in numerical methods by using a system of equations that takes into account the units of each variable. This ensures that the units of the final solution are consistent with the units of the initial conditions. This is important in scientific calculations, as it allows for more accurate and meaningful results.

3. Why is maintaining units important in numerical methods?

Maintaining units in numerical methods is important because it ensures that the results of the calculations are consistent with the physical units of the problem. Without considering units, the final solution may not make sense or may be completely incorrect. Units also provide a way to check the accuracy of the calculations.

4. What is the order of accuracy for the Runge-Kutta method?

The order of accuracy for the Runge-Kutta method depends on the number of stages used in the algorithm. For example, the classic fourth-order Runge-Kutta method has an order of accuracy of four, meaning that the error is proportional to the fourth power of the step size. Higher order methods, such as the fifth-order Runge-Kutta method, have a higher accuracy.

5. Can the Runge-Kutta method be used to solve any type of differential equation?

The Runge-Kutta method can be used to solve a wide range of ordinary differential equations, including first-order and higher-order equations. It is also applicable to stiff equations, which are equations that are difficult to solve due to large differences in the scales of the variables. However, it may not be the most efficient or accurate method for certain types of differential equations, such as partial differential equations.

Similar threads

Replies
56
Views
699
  • Differential Equations
Replies
2
Views
2K
  • Differential Equations
Replies
1
Views
1K
  • Differential Equations
Replies
6
Views
3K
  • Differential Equations
Replies
4
Views
6K
Replies
9
Views
2K
Replies
7
Views
2K
  • Differential Equations
Replies
31
Views
6K
Replies
2
Views
2K
  • Differential Equations
Replies
4
Views
2K
Back
Top