I want to progress step by step. Would you please guide me about my code below? I want to get acc=-10*t values between t=0 and t=1 with step size 0.001
And I am sorry to say but you should start moving to const instead of #define if you are coding in C++.
Edit:
wait,, you should never use a floating point as an index if you don't really know the consequences. You should probably use integer instead and converts them to double when you need to use the data.
I will guide you after all my understanding of what you want to do is confirmed.
Dear Friend,
Thanks a lot for your comments. I do not know if I should store the data in acc array or not. But I need those data to be used in other function and calculate the velocity but I postponed it to after this step as I want to learn this gradually.
Totally in this step I want to get acceleration data with its function between time 0 and 1 and time step 0.001 and show it in a table.
Bu later I want to use the acceleration data to calculate the velocity and position by using numerical method below:
f(x+1)=dt/2*(f'(x+1)-f'(X))-f(x)
I mean something like this:
acc[time_step]=-10*time_step;
}
//--------------------------------------------------------------------------
// to integrate equation du/dt=a
void solve_u(double *u, double *acc, double dt, int time_step){
change every time to millisecond and store it in an int,, I suggest if you want to array that way
but I think it's actually more reasonable to just use function and not store it in an array.
I don't know what you are using this for but suit your needs
In 2D Physics engine it's usually something like this
1 2 3 4 5 6 7 8 9 10 11 12 13
float a = -10.0;
float v = 10.0;
float y = 10.0;
constfloat timestep = 0.001;
constfloat start = 0;
constfloat end = 1;
for( float i = 0; i < end; i += timestep ){
v += a*dt;
y += v*dt;
}
I know that this is by no means a perfect calculation but it's usually negligible in computer graphics because there is no almost difference between 100px and 101px