My Math Forum Basic question about low-order RK

 Differential Equations Ordinary and Partial Differential Equations Math Forum

 June 22nd, 2017, 06:22 AM #1 Newbie   Joined: Jun 2017 From: italia Posts: 13 Thanks: 2 Basic question about low-order RK At a given instant $\displaystyle t_i$, a body is moving in the atmosphere with velocity $\displaystyle \vec v_i$. I need to know the velocity after an arbitrary interval of time. I calculate: $\displaystyle \vec a_i= k \cdot v^2_i \cdot \frac {\vec v_i} {|\vec v_i|}$ The velocity $\displaystyle \vec v_{i+1}$ at time $\displaystyle t_{i+1} = t_i + \Delta t$ is $\displaystyle \vec v_{i+1}= \vec a_i \cdot \Delta t$. I would speed up my simulation while retaining a good accuracy and I thought to use a low-order Runge-Kutta method; a second-order RK would be a good starting point, but unfortunately my math skill is poor (like my English ). Please, would somebody help me in writing a second-order RK method for this problem?
June 22nd, 2017, 09:06 PM   #2
Senior Member

Joined: Feb 2016
From: Australia

Posts: 1,737
Thanks: 606

Math Focus: Yet to find out.
Quote:
 Originally Posted by Cristiano At a given instant $\displaystyle t_i$, a body is moving in the atmosphere with velocity $\displaystyle \vec v_i$. I need to know the velocity after an arbitrary interval of time. I calculate: $\displaystyle \vec a_i= k \cdot v^2_i \cdot \frac {\vec v_i} {|\vec v_i|}$ The velocity $\displaystyle \vec v_{i+1}$ at time $\displaystyle t_{i+1} = t_i + \Delta t$ is $\displaystyle \vec v_{i+1}= \vec a_i \cdot \Delta t$. I would speed up my simulation while retaining a good accuracy and I thought to use a low-order Runge-Kutta method; a second-order RK would be a good starting point, but unfortunately my math skill is poor (like my English ). Please, would somebody help me in writing a second-order RK method for this problem?
Any initial conditions for velocity and acceleration? Or do you just want the general form?

Using RK2 with 2 coupled DE's will result in four function evaluations.

You could assign $\dfrac{dv}{dt} \equiv f(t, v)$, and $\dfrac{ds}{dt} \equiv g(t,a)$. The RK2 scheme would look like,

$\Delta t = h$

$f_1 = h f(t_i, v_i)$

$g_1 = h g(t_i, a_i)$

$f_2 = h f(t_i + \frac{h}{2}, v_i + \frac{f_1}{2})$

$g_2 = h f(t_i + \frac{h}{2}, a_i + \frac{g_1}{2})$

$a_{i+1} = f_i + f_2$

$v_{i+1} = g_i + g_2$

$t_{i+1} = t_i + h$

 June 22nd, 2017, 09:18 PM #3 Senior Member   Joined: Feb 2016 From: Australia Posts: 1,737 Thanks: 606 Math Focus: Yet to find out. I have to ask, why RK2? For a system like this, i don't see any trouble in using RK4 or some variant. In any case, the software you are using to simulate this will likely have a built in differential equation solver. In matlab, this would be ode45(). From memory, it is the Runge-Kutta-Fehlberg method. Which is a bit more accurate that the RK4.
 June 23rd, 2017, 03:32 AM #4 Newbie   Joined: Jun 2017 From: italia Posts: 13 Thanks: 2 Thanks a lot for the clear answer! In the working versions of my simulations, I use the 8th-order Dormand-Prince integrator (DOPRI 853, with 3rd-order error estimation and continuous output), but I don't understand what I'm doing; I just put the acceleration formula in the derivative function and then I start the simulation (typically an n-body problem or an "atmospheric" problem). I hope that if I start to write a simple RK integrator from scratch, I should understand how it works and I should stop asking for help every time I need to write a simulation. Now I'll try to code what you wrote... Thank you.
June 23rd, 2017, 05:59 AM   #5
Senior Member

Joined: Apr 2014
From: Glasgow

Posts: 2,132
Thanks: 717

Math Focus: Physics, mathematical modelling, numerical and computational solutions
Quote:
 Originally Posted by Cristiano I hope that if I start to write a simple RK integrator from scratch, I should understand how it works and I should stop asking for help every time I need to write a simulation. Now I'll try to code what you wrote... Thank you.
If you want to take an in-depth look at numerical methods, try getting hold of a copy of Numerical Recipes (in C or Fortran). It's brilliant and will help you a lot even if you don't code anything in C or Fortran.

 June 23rd, 2017, 08:02 AM #6 Newbie   Joined: Jun 2017 From: italia Posts: 13 Thanks: 2 I have the 3rd edition of NR in C and it's very useful, but a question & answer thread helps a lot. Thanks from Benit13

 Tags basic, loworder, question, runge-kutta

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post john beattie New Users 1 September 17th, 2015 11:42 AM genieboy Elementary Math 4 November 15th, 2012 04:28 AM OriaG Linear Algebra 1 November 7th, 2012 06:21 PM Dudewithmathproblems Algebra 12 February 6th, 2012 01:37 PM WannaBe Applied Math 0 October 24th, 2010 01:36 PM

 Contact - Home - Forums - Cryptocurrency Forum - Top