# Runge Kutta , please save me

1. Jan 16, 2010

### choppu

Hi,

I have got a coupled Differential equation :

$$\ x_1''\ =\ \frac{F_1}{M_1}\ =\ \gamma\cdot{}\left[-\,\frac{M_S}{|\overrightarrow{x_1}|^3}\cdot{}\overrightarrow{x_2}+\frac{M_2}{|\overrightarrow{x_2-x_1}|^3}\cdot{}(\overrightarrow{x_2-x_1})\right]$$

$$\ x_2''\ =\ \frac{F_2}{M_2}\ =\ \gamma\cdot{}\left[-\frac{M_S}{|\overrightarrow{x_2}|^3}\cdot{}\overrightarrow{x_1}+\frac{M_1}{|\overrightarrow{x_2-x_1}|^3}\cdot{}(\overrightarrow{x_2-x_1})\right]$$

and i need to solve it numerically using the RUNGE-KUTTA method, however I have no clue how to do that .

Last edited: Jan 16, 2010
2. Jan 16, 2010

### D H

Staff Emeritus
What have you been taught? Certainly the instructor did not just say "here are some differential equations. Write a numerical integrator to solve them." (You will have to wait until you are an employee to have that kind of joy.)

Please remember that our role here is to students do their own homework. You need to show some work before we can start on that path.

3. Jan 16, 2010

### choppu

I have solved it with the Euler Algorithm. I have really never used/seen the Runge-Kutta before.

I wrote a programme . (using the Euler) Shall I send you the programme to proof my work?

Will you help me out then?

Thank you.

choppu

4. Jan 16, 2010

### D H

Staff Emeritus
What have you been taught about Runge-Kutta methods?

Which Runga-Kutta method (there are several) are you supposed to be using?

5. Jan 16, 2010

### choppu

We should use the Runge-Kutta of the Second Order...

We have been taught that they are an improvement to the Euler-Algorithm and that they use the slope of both sides instead of just one.

However I have no clue how to apply this.

6. Jan 16, 2010

### choppu

Ok,

I will post the Euler computation excerpt of my code. Maybe somebody will have mercy and tell me how to modify it to transform it to Runge-Kutta:

Code (Text):

int m1 = 6000;
int m2 = 8000;
double gamma = 6.67;
double r = 15;
double r2 = 20;
double vx = 0;
double vx2 = 0;
double alpha = 0;
double alpha2 = 0;
double alpha3 = 0;
double alpha4 = 0;
double x = r;
double x2 = r2;
double y = 0;
double y2 = 0;
double mittelpunktx = b/2;
double mittelpunkty = h/2;
double vy = 0.0001 * Math.sqrt(1000 * gamma * m / r);
double vy2 = 0.0001 * Math.sqrt(1000* gamma * m / r2);
//double tend = 500;
double t = 0;
double pi = 4*Math.atan(1);
double deltat = 0.2;
double result = 0;

while (t <= tend) {

t = t + deltat;
r = Math.sqrt(x * x + y * y);
r2 = Math.sqrt(x2 * x2 + y2 * y2);

double posx = mittelpunktx + x;
double posy = mittelpunkty + y;
double posx2 = mittelpunktx + x2;
double posy2 = mittelpunkty + y2;
double poswechselx = posx2 - posx;
double poswechsely = posy2 - posy;
double rwechselq = poswechselx * poswechselx + poswechsely * poswechsely;

double a = 0.00001 * gamma * ((m / r) / r);
double a2 = 0.00001 * gamma * ((m / r2) / r2);
double avon1auf2 = 0.00001 * gamma * (m2 / rwechselq);
double avon2auf1 = 0.00001 * gamma * (m1 / rwechselq);

alpha = winkel(x,y,alpha);
alpha2 = winkel(x2, y2, alpha2);
alpha3 = winkel(poswechselx, poswechsely, alpha3);
alpha4 = alpha3 + pi;

double ax = a * Math.cos(alpha);
double ay = a * Math.sin(alpha);
double ax2 = a2 * Math.cos(alpha2);
double ay2 = a2 * Math.sin(alpha2);
double ax3 = avon1auf2 * Math.cos(alpha4);
double ay3 = avon1auf2 * Math.sin(alpha4);
double ax4 = avon2auf1 * Math.cos(alpha3);
double ay4 = avon2auf1 * Math.sin(alpha3);

ax = ax + ax3;
ay = ay + ay3;
ax2 = ax2 + ax4;
ay2 = ay2 + ay4;
vx = vx - ax * deltat;
vy = vy - ay * deltat;
x = x + vx * deltat;
y = y + vy * deltat;
vx2 = vx2 - ax2 * deltat;
vy2 = vy2 - ay2 * deltat;
x2 = x2 + vx2 * deltat;
y2 = y2 + vy2 * deltat;
the winkel() method is used to achieve the correct angle (like in the complex plane).

7. Jan 17, 2010

### ideasrule

The problem is that we don't know exactly what it is you want help with. You seem to understand what the Euler method is about, and the Runge-Kutta method is only infinitesimally more complicated, so what are you having trouble with? Here is a description of the second-order Runge-Kutta method:

http://www.swarthmore.edu/NatSci/echeeve1/Ref/NumericInt/RK2.html

If you have dv/dt=GM/r^2, then you calculate dv/dt and use it to predict r a timestep in advance, just like in the Euler method. You then use this predicted r to calculate dv/dt, average the two dv/dt's that you've calculated, and use that average to calculate that r that you're going to use.

8. Jan 18, 2010

### Redbelly98

Staff Emeritus
You'll need to convert this to four 1st-order equations in order to use Runge-Kutta methods.

So for example, define
x1' = x3
so that
x3' = γ · [...]
and similarly for x2