943,663 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 564
  • C RSS
Oct 22nd, 2008
0

Setting up counter.

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
IrishUpstart is offline Offline
13 posts
since Sep 2008
Oct 22nd, 2008
0

Re: Setting up counter.

You could try a double variable, like this:
  1.  
  2. for (float c=0.0;c<2.1;c+=0.02) {
  3. ...
  4. }
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.
Last edited by Chaster; Oct 22nd, 2008 at 10:27 am.
Reputation Points: 12
Solved Threads: 3
Junior Poster in Training
Chaster is offline Offline
68 posts
since Jun 2007
Oct 22nd, 2008
0

Re: Setting up counter.

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):
  1. double t;
  2. int i;
  3.  
  4. for (t = 0.0,i = 0; i <= 100; ++i, t = i/50.0) {
  5. .....
  6. }
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...
Reputation Points: 1234
Solved Threads: 347
Postaholic
ArkM is offline Offline
2,001 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Divide and conquer?
Next Thread in C Forum Timeline: Sorting in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC