Would you be so kind to change algorithm for solving this system
d2_x/dt_2=-GMx/(x^2+y^2)^(3/2)
d2_y/dy_2=-GMy/(x^2+y^2)^(3/2)
algorithm name is Runge-Cute Method
#include <stdio.h>
#include <stdafx.h>
#include <math.h>
#include <iostream>
using namespace std;
double f(int i,double x,double y[4]){
switch (i){
case 1:return y[4];break;
case 2: return y[1];break;
case 3:return y[2];break;
case 4:return y[3];break;
default : break;
}
}
void step(double x,double h,int n,double y[4])
{
int i=0;
double yt[4];
double k1[4];
double k2[4];
double k3[4];
double k4[4];
for(i = 1; i <= n; i++)
{
k1[i] = h*f(i, x, y);
}
for(i = 1; i <= n; i++)
{
yt[i] = y[i]+0.5*k1[i];
}
for(i = 1; i <= n; i++)
{
k2[i] = h*f(i, x+h*0.5, yt);
}
for(i = 1; i <= n; i++)
{
yt[i] = y[i]+0.5*k2[i];
}
for(i = 1; i <= n; i++)
{
k3[i] = h*f(i, x+h*0.5, yt);
}
for(i = 1; i <= n; i++)
{
yt[i] = y[i]+k3[i];
}
for(i = 1; i <= n; i++)
{
k4[i] = h*f(i, x+h, yt);
}
for(i = 1; i <= n; i++)
{
y[i] = y[i]+(k1[i]+2.0*k2[i]+2.0*k3[i]+k4[i])/6;
}
}
void solvesystemrungekutta(double x,double x1,int steps,double result[4]){
for(int i = 1; i <= steps-1; i++)
{
step(x+i*(x1-x)/steps, (x1-x)/steps,4, result);
}
}
int _tmain(){
//???µ?€???°?
Runge-Cute Method for solving system of differentional equat
- t00fri
- Developer
- Posts: 8772
- Joined: 29.03.2002
- Age: 22
- With us: 22 years 10 months
- Location: Hamburg, Germany
Terance wrote:You're right )))))))my english isnt so good/t00fri wrote:Just a little math background (can't hurt, can it?):
These equations are called differential equations
and the method you were referring to is by two gentlemen, named
Runge-Kutta
"Runge-Cute" sounds cute, I must admit, yet...
F.
Runge-"Cute" is not a matter of English, since these are names.
It's more a matter of mathematics...
English is also not my mother tongue.
F.
-
- Developer
- Posts: 944
- Joined: 18.07.2002
- With us: 22 years 6 months
- Location: Lyon (France)
Its dangerous to play with these solvers without some understanding of how they work. If you have no background in numerical analysis, then I suggest you start with Numerical Recipes in C++. While the code has limitations, the explanation as to how the beasts work is good. netlib has more complex codes. If you are in difficulties with esoteric equations and problems, then the usenet group sci.math.num-analysis is a good place to ask for help but you really need to have the background first.