My Math Forum Numerical integration with 3 variables

 Differential Equations Ordinary and Partial Differential Equations Math Forum

 August 25th, 2017, 03:29 AM #1 Newbie   Joined: Jun 2017 From: italia Posts: 9 Thanks: 1 Numerical integration with 3 variables I have 3 variables: v, b and h. I know how to calculate v’, b’ and h’. Starting the simulation from an initial condition, I need to calculate v, b and h after a given time using a numerical integrator (say RK4). If I use the simple Euler method, I write; v= v + dt * v’ b= b + dt * b’ h= h + dt * h’ but when I switch to RK4, I don’t know what to write. For example: h’= v * cos(b) and the RK4 function is of the form y(t + dt)= rk4(dx, x, y(t)), while the acceleration function is of the form acc= f(x, y); what should I write in place of x and y? The simulation is explained here: https://mintoc.de/index.php?title=Gravity_Turn_Maneuver
August 25th, 2017, 04:04 AM   #2
Senior Member

Joined: Feb 2016
From: Australia

Posts: 1,518
Thanks: 506

Math Focus: Yet to find out.
Quote:
 Originally Posted by Cristiano I have 3 variables: v, b and h. I know how to calculate v’, b’ and h’. Starting the simulation from an initial condition, I need to calculate v, b and h after a given time using a numerical integrator (say RK4). If I use the simple Euler method, I write; v= v + dt * v’ b= b + dt * b’ h= h + dt * h’ but when I switch to RK4, I don’t know what to write. For example: h’= v * cos(b) and the RK4 function is of the form y(t + dt)= rk4(dx, x, y(t)), while the acceleration function is of the form acc= f(x, y); what should I write in place of x and y? The simulation is explained here: https://mintoc.de/index.php?title=Gravity_Turn_Maneuver
I'm not quite sure what differential equations you are trying to solve exactly. Can you write them explicitly?

 August 25th, 2017, 04:37 AM #3 Newbie   Joined: Jun 2017 From: italia Posts: 9 Thanks: 1 Your post is useful when I have only one equation, but since I have a poor math background, when I need to solve a slightly complicate problem, I don't know what to do. In this case, I need to solve the equation $\dot v = ...$ and $\dot b = ...$ showed here (please, don't ask me to rewrite those very long equations ). For example, b'= rk4(dx, x, y), where dx and x are times and y is b, but I have that $\dot b = f(b, v, h)$. What should I write inside the function to calculate the acceleration for b'?
 August 25th, 2017, 08:37 AM #4 Global Moderator     Joined: Oct 2008 From: London, Ontario, Canada - The Forest City Posts: 7,742 Thanks: 1000 Math Focus: Elementary mathematics and beyond The resulting optimal control problem is given by where $F_{max}$ is the maximum thrust of the vehicle's engine and $\varepsilon$ is a small number that is strictly greater than zero. The differential states of the problem are $m, v, \beta, h, \theta$ while $u$ is the control function. Last edited by greg1313; August 25th, 2017 at 08:42 AM.
 August 25th, 2017, 09:08 AM #5 Newbie   Joined: Jun 2017 From: italia Posts: 9 Thanks: 1 Is my link not working?
September 3rd, 2017, 08:51 PM   #6
Senior Member

Joined: Feb 2016
From: Australia

Posts: 1,518
Thanks: 506

Math Focus: Yet to find out.
Quote:
 Originally Posted by Cristiano Is my link not working?
Sorry.. I didn't realise it was you who started the other thread I linked!

You definitely want to write the sim from scratch? Which language/software?

Also are you sure you need to use an RK algorithm? MATLAB has inbuilt functions for solving optimisation problems like the one in the link.. although to be honest with you, I'm not sure if these can be used for constraints that include differential equations.. interesting ..

September 4th, 2017, 08:53 AM   #7
Newbie

Joined: Jun 2017
From: italia

Posts: 9
Thanks: 1

Quote:
 Originally Posted by Joppy You definitely want to write the sim from scratch? Which language/software?
In the meanwhile, I wrote my C++ simulation which uses several RK algorithms.

We have:
v’ = f(t, v)
g’ = f(g, v)
h’ = f(g, v)
x’ = f(g, v)

Let’s consider for a moment the RK2 algorithm. I do (in pseudo-code) [it seems that I don't know how to format the text to make it more readable]:

k1= stp * fv(t, v); k2= stp * fv(t + stp * .5, v + .5 * k1); v += k2;
k1= stp * fg(g, v); k2= stp * fg(g + .5 * k1, v); g += k2;
k1= stp * fh(g, v); k2= stp * fh(g, v); h += k2;
k1= stp * fx(g, v); k2= stp * fx(g, v); x += k2;

I use the updated v and the updated g as the input for the next functions; is that correct? Or should I update v and h after the calculation of g, h and x?

Quote:
 Originally Posted by Joppy Also are you sure you need to use an RK algorithm? MATLAB has inbuilt functions for solving optimisation problems like the one in the link.. although to be honest with you, I'm not sure if these can be used for constraints that include differential equations.. interesting ..
I would use that simulation to understand how RK works and how to use it in any situation, without asking every time.
Since I always wrote a program for a new simulation, I cannot use MATLAB, Mathematica or whatever; I need to code in C++.

 Thread Tools Display Modes Linear Mode

 Similar Threads Thread Thread Starter Forum Replies Last Post Yooklid Math Software 11 March 27th, 2017 12:47 AM AnomanderRakeSoD Applied Math 0 June 21st, 2013 03:11 AM Albert.Teng Calculus 3 July 1st, 2012 11:13 PM dallairius Calculus 1 April 6th, 2012 10:07 AM PageUp Applied Math 1 March 19th, 2012 06:58 AM

 Contact - Home - Forums - Cryptocurrency Forum - Top