# Runge Kutta - units

• A
Roboto
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?

Homework Helper
Gold Member
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?

K Murty
Roboto
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.

Homework Helper
Gold Member
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.

Roboto
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?

Homework Helper
Gold Member
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.

Roboto
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

Homework Helper
Gold Member
Except that k2 is a function of (un+(h/2)*k1,t+h/2), not equivalent to un+(h/2)*k1, correct?

Roboto
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.

mpresic3
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.

mpresic3
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.

Gold Member
BTW, if you use Latex, your equations will be clearer (and easier to write).
yn+1=yn+(h/6)*(k1+2*k2+2*k3+k4)

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.

Homework Helper
Gold Member
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

Fourth order Runge-Kutta basically uses the Taylor series expansion. The Taylor series expansion should have the right units.

Last edited:
scottdave
Homework Helper
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

scottdave
Homework Helper
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
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....
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://www.physicsforums.com/threads/runge-kutta-units.950705/", "fetch_time": 1669624479000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2022-49/segments/1669446710488.2/warc/CC-MAIN-20221128070816-20221128100816-00286.warc.gz", "warc_record_offset": 991780532, "warc_record_length": 22700, "token_count": 2459, "char_count": 8551, "score": 3.59375, "int_score": 4, "crawl": "CC-MAIN-2022-49", "snapshot_type": "latest", "language": "en", "language_score": 0.9308690428733826, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00009-of-00064.parquet"}