- #1
platipo
- 14
- 0
I've been browsing the forum, but I haven't found a way to solve this thing, which has been frustrating me for quite a while, I'm trying to develop a simulation of cue formation and propagation on cars on a single lane road, and of course, I have to compute the acceleration of vehicles obeying a certain car-following dynamic. I have a working Euler method, but I wanted to make it a Runge Kutta second order. And I can't... it's been two weeks now, I'm growing frustrated.
anyway, here's the "relevant" code, the function that I'm iterating over time.
whenever I run this, the car after the first (which is of course just oscillating) brakes pretty hard, and quickly becomes stationary, with all the ones following reasonably doing the same. I Thank you in advance for any possible help, I found out about this forum just a couple of days ago and I find it really great. Sorry for my poor english, I'm doing my best...
anyway, here's the "relevant" code, the function that I'm iterating over time.
Code:
void next(void){
int n;
double xw[CAR_NUMBER+1],uw[CAR_NUMBER+1];
double C=AMPLI/OMEGA;
u[CAR_NUMBER] = U0+AMPLI*cos(PI*OMEGA*t);
x[CAR_NUMBER] = U0*t+C*sin(PI*OMEGA*t);
// the first car in the cue is accelerating and braking periodically to perturbate the cue
Force(x,u,t+dt/2);
//the Force function returns a[n] which is the acceleration, I know it works, it gives no problem at all with the euler method
fprintf(fpx,"%10.3lf ",a[CAR_NUMBER-1]);
for( n=0; n<CAR_NUMBER; n++ ){
xw[n]= x[n] +u[n]*dt/2;
uw[n]= u[n] +a[n]*dt/2;
}
//end of the trial step
Force(xw,uw,t+dt);
for( n=0; n<CAR_NUMBER; n++ ){
x[n]= x[n] +uw[n]*dt;
u[n]= u[n] + a[n]*dt;
}
//end of the second and final step
t=t+dt;
}
whenever I run this, the car after the first (which is of course just oscillating) brakes pretty hard, and quickly becomes stationary, with all the ones following reasonably doing the same. I Thank you in advance for any possible help, I found out about this forum just a couple of days ago and I find it really great. Sorry for my poor english, I'm doing my best...