help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## Re: [Help-gsl] RK4 Help required

 From: Pau Cervera Badia Subject: Re: [Help-gsl] RK4 Help required Date: Tue, 08 May 2007 11:26:20 +0200 User-agent: Thunderbird 1.5.0.10 (X11/20070403)

Since gsl solvers solve systems of first order differential equations of the type:
```
x' = f(x,t) (where the prima is the time derivative)

```
where x is a vector of positions, and f(x,t) is the vector of forces you have to implement via the func that is passed via gsl_odeiv_system to the gsl solver, you should consider making a vector x of 3 times longer than the number of charges you have.
```
For instance, you can order your components in a 12-vector as,

x_0, y_0, z_0, x_1, y_1, z_1, x_2, y_2, z_2, x_3, y_3, z_3.

To help you to extract the right components, you can define the macros,

#define xindex(i) 3 * i
#define yindex(i) 3 * i + 1
#define zindex(z) 3 * i + 2

and access the position of particle i as

double x_i = sys[xindex(i)];
double y_i = sys[yindex(i)];
double z_i = sys[zindex(i)];

when needed.

Good luck,

cigdem ozkan wrote:
```
```Hi again,
I am posting a smaller version of my question rearding rk4 since I didnt get a
reply and I am really anxious for some feedback.

I have the following fuction:
dxi/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. Input for the initial values: q = { 1.0, 1.0, -1.0, 1.0 } charge x0 = { 1.0, 2.3, 3.2, 4.0 } init posn x
```y0 = { 1.0, 2.4, 3.0, 4.0 } init posn y
z0 = { 1.0, 2.5, 3.3, 4.2 } init posn z
QUESTION:
```
Since there are two values for each coordinate (i and j), how can I write the function in an acceptable form for RK4? I would appreciate any feedback concerning RK4.
```Thanks for your time,
C.

```
---------------------------------
```Ahhh...imagining that irresistible "new car" smell?
Check outnew cars at Yahoo! Autos.
_______________________________________________
Help-gsl mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gsl

```
```
--
Pau Cervera i Badia (e-mail address@hidden)
{
Departament de Física Fonamental               Martí i Franqués, 1
Universitat de Barcelona                 Planta 3, despatx 346 bis
08028 Barcelona
tel: +34 934 039 708                                         Spain

"Simple things should be simple, complex things should be possible."
-- Alan Kay
return http://www.ffn.ub.es/%7Ecervera/
}

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]