[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] a basic question concerning RK4
From: |
cigdem ozkan |
Subject: |
[Help-gsl] a basic question concerning RK4 |
Date: |
Fri, 4 May 2007 02:48:22 -0700 (PDT) |
Hey there,
I have a technical question but one has to go through the story to understand
what I am tyring to achieve. I hope you can find the time to do so. It is very
basic physics so it only requires patience to read through the rest of my email
:) Thank you already.
I am trying to simulate the Coulomb repulsion between charged particles. I am
using RK4 to do this which requires a function. The physics formula of the
function is:
dx/dt = k*qi*(xi-xj)/sqrt((xi-xj)^2+(yi-yj)^2+(zi-zj)^2)
where qi is the charge of the i-th particle, xi, yi, zi are the coordinates of
the i-th particle and xj, yj,zj are the coordinates of the j-th particle.
As an input for the initial values of the positions and charge for each
particle, I am using arrays (currently only for 4 particles):
q[4] = { 1.0, 1.0, -1.0, 1.0 } charge
x0[4] = { 1.0, 2.3, 3.2, 4.0 } init posn x
y0[4] = { 1.0, 2.4, 3.0, 4.0 } init posn y
z0[4] = { 1.0, 2.5, 3.3, 4.2 } init posn z
and by using two "for" loops I can loop through each particle and compute the
value of the total effect of all the particles on eachother.
My question is: since there are two values for each coordinate (i and j), how
can I write the function in an acceptable form for RK4?
I did try the following:
int func (double t, const double y[], double f[], void *params){
double mu = *(double *)params;
double dx = (y[0]-y[1])/r;
double dy = (y[2]-y[3])/r;
double dz = (y[4]-y[5])/r;
f[0] = mu*y[6]*dx/(r*r);
f[1] = mu*y[6]*dy/(r*r);
f[2] = mu*y[6]*dz/(r*r);
return GSL_SUCCESS;
}
however, I am not convinced this is correct (at all) and as it is I have to
specify too many initial values for y (ie, y[0], y[1],...y[7]) and it fails
miserably.
I would appreciate any feedback especially if someone has HAD to do something
similar.
Cheers.
Best,
C.
---------------------------------
No need to miss a message. Get email on-the-go
with Yahoo! Mail for Mobile. Get started.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-gsl] a basic question concerning RK4,
cigdem ozkan <=