Help,
the particle should go forth and back and each time he's reaching the wall (+1;-1), he should loss velocity, hence energy! But this results in incomensurability = the new dx doesn't fit into the intervall [-1;1]; here's the code:
Code:double x=0.0; double vx=0.43; int i , frac=7 ; double tx=fabs(1/vx); double dx=vx*tx/frac; for (i=0 ; i<=N ; x+=dx , i++) { printf("%i %.4f\n",i,x); fprintf(f_ptr,"%i %.4f\n",i,x); if(x<-0.99 || x>0.99) dx*=-1.0;