#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#include <time.h>

#include "functions.h"

double *time(double *x,double *y,double *z,double *vx,double *vy,double *vz,long int N, double h, long int T,double **bx,double **by,double **bz)

{

//we declare the variables

int i, k, t, l, m;

double **ax, **ay, **az;

t=(int)(T/h);

//allocation of memory

ax= (double**) calloc(N,sizeof(double*));

for(l=0; l<N; l++)

{

ax[l]= (double*) calloc(t+2,sizeof(double));

}

ay= (double**) calloc(N,sizeof(double*));

for(l=0; l<N; l++)

{

ay[l]= (double*) calloc(t+2,sizeof(double));

}

az= (double**) calloc(N,sizeof(double*));

for(l=0; l<N; l++)

{

az[l]= (double*) calloc(t+2,sizeof(double));

}

//we set the initial value of the variables

for (i=0;i<N;i++)

{

ax[i][0]=x[i];

ay[i][0]=y[i];

az[i][0]=z[i];

bx[i][0]=vx[i];

by[i][0]=vy[i];

bz[i][0]=vz[i];

}

//we evolve the system of particles, making them move according to their speed

k=0;

do{

i=0;

do

{

if (ax[i][k]>=1)

{ bx[i][k+1]=-bx[i][k];}

else if (ax[i][k]<=0)

{ bx[i][k+1]=-bx[i][k];}

else { bx[i][k+1]=bx[i][k];}

if (ay[i][k]>=1)

{ by[i][k+1]=-by[i][k];}

else if (ay[i][k]<=0)

{ by[i][k+1]=-by[i][k];}

else { by[i][k+1]=by[i][k];}

if (az[i][k]>=1)

{ bz[i][k+1]=-bz[i][k];}

else if (az[i][k]<=0)

{ bz[i][k+1]=-bz[i][k];}

else { bz[i][k+1]=bz[i][k];}

ax[i][k+1]=ax[i][k]+bx[i][k+1]*h;

ay[i][k+1]=ay[i][k]+by[i][k+1]*h;

az[i][k+1]=az[i][k]+bz[i][k+1]*h;

i++;

} while (i<N);

k++;

}while ((h*k)<T);

m=k;

//free memory

for(l=0; l<N; l++)

{

free(ax[l]);

free(ay[l]);

free(az[l]);

}

free(ax);

free(ay);

free(az);

return 0;

}

Tweet This+ 1 thisPost To Linkedin