0

So I need to create a set of data points for the function v*t+.5at(squared). The data points need to be every .02 seconds from 0 to 2.0 seconds. How do I set up the counter for that? Also, all of these points need to be wrote to a location so that I can try to graph them. What would be the best way to do that?

Thanks in advance

3
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by ArkM
0

You could try a double variable, like this:

for (float c=0.0;c<2.1;c+=0.02) {
        ...
    }

Inside that for, you compute the values for your function, then you save these either in an array of type double, or (if you want them to be available later) into a text file.

0

Never use this approach in math calculations: 0.02 is a double type approximation of the real number 0.02 so 100*0.02 != 2.0.
In that case you have 100 intervals (and 101 points):

double t;
int i;

for (t = 0.0,i = 0; i <= 100; ++i, t = i/50.0) {
   .....
}

In that case you also have a ready-to-use index to place all needed values in arrays (to plot graph etc)...
To avoid time expensive conversions of i var from int type to double type you can add in the loop header auxiliary double "index" variable. As usually, no need in this optimization...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.