ok, so basically heres my problem...in my program i have to write to my output file column of time, against x(t)..so i have to output time[i] and x[i], where
time[0]=0 and x[0] is given by reader input.
but i have to only display time until some parameter known as p..But I cant seem to get it to stop when time[i]<p..it just keeps on listing time for all values up to the size of my array..with a while loop i can get time[i]<p but then my values of x[i] are all 0 which is cleary wrong..just need some tips on how to constuct the loops..at the moment it looks like this:
Code:
time[0]=0;
time_increment =1.0;
fprintf(output, "%f %f\n", time[0], x[0]);
i=0;
i++;
while((time[i]>=0)&&(time[i] < p))
{
i++;
time[i] = i*time_increment;
v[i+1] = v[i] - (g*v[i] + w2*x[i])*time_increment + (1/m)*f[i]*time_increment;
x[i+1] = x[i] + v[i+1]*time_increment;
fprintf(output, "%f %f\n", time[i], x[i]);
}
also, as u can see i cant seem to get it to display time[0] and x[0] automically for i=0, in my output file..how can i fix this?
thanx for any help at all!
}
my first draft i used a for loop, but i did not know what the statment to be evaluted could be other than time[i]<p, which clearly doesnt work for the for loop.
Code:
for(i=0; time[i] <p; i++)
{
time[i] = i*time_increment;
v[i+1] = v[i] - (g*v[i] + w2*x[i])*time_increment + (1/m)*f[i]*time_increment;
x[i+1] = x[i] + v[i+1]*time_increment;
fprintf(output, "%f %f\n", time[i], x[i]);
}