Simple SIn Curve

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akinidu
    New Member
    • May 2010
    • 7

    Simple SIn Curve

    I just move from Matlab to C ;;;;;

    I am trying to plot a Simple sin curve in C
    Code:
     
    
    #include <math.h>
    #include <stdio.h>
    
    #define PI 3.1415926535897932384626433832795l
    
    int main()
    {
      const float dt = .001;
      int i, n ;
      float  t,t1, y;
      t=0.0;
      n=20;
      printf(" i             t                   y \n");
      printf("------------------------------------ \n");
      for (i = 0; i <= n; i++)
      {
         t1=i*dt;
         y = sin(2*PI*t1);
         printf("%d %5e %2e \n", i, t1, y);
      }
      return 0;
    }

    I have few questions !

    1. How i can get out put in terms of dat file ! I want to plot it in matlab later
    2. In Matlab, when i run the same algorithmi get negative amplitudes also but here i am getting all positive ! This means my code is wrong some where
    3. Also if i want to take random values of t1 instead of uniform ! suppose i want to chuck of 10% from this what should i do


    Thanks
  • akinidu
    New Member
    • May 2010
    • 7

    #2
    Oh its fine i corrected this code but still i am not able to figure it out how can i chop of 30% of values from this curve randomly....... ........i wabt to use rand not srand as i am looking for chopping 5% fst then 10%..slowly slowly 50%

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      I don't know if this is important to you but a float contains only 6 significant digits. A double has only 15.

      Comment

      Working...