Programming an equation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gamperz23
    New Member
    • Sep 2009
    • 1

    Programming an equation

    At time t, the velocity v of an object undergoing simple harmonic motion at the end of a spring is given by the formula


    v = A * √ k / m * cos ( √ k / m * t )

    Here, m is the mass of the object (in g), k is a constant depending on the spring (in g / s2), A is the maximum distance the object moves, and t is the time (in s).
    Write a C program which accepts as inputs a time t, mass m, constant k, and distance A, and which computes the velocity of the object according the formula above.
    When running your program, use the following inputs:
    t: 0.10 s
    m: 36.0 g
    k: 400 g / s2
    A: 5.0 cm
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

    Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

    Then when you are ready post a new question in this thread.

    Banfa
    Administrator

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      This appears to be a very simple assignment even though it may take some debugging because of units. Here are the bare bones.
      Since k is a spring constant you should declare it as a const.
      Likewise for pi.
      Since sqrt(k/m) appears twice in the formula assign a variable to it (say z).
      Now you can simplify the solution by:
      Code:
      cin>>t>>m>>A; //get the 3 variables, (k already declared).
        v=A*z;
       v*=cos(z*t);//calculate v (rememeber cos (arguement) in radians (deg*pi/180)
      cout<<v;

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Following up on whodgson's comment that the cos() function in C requires an argument in radians ...

        Your formula requires you to compute the cosine of squareRoot(k/m)*t. This cosine argument is dimensionless. Your problem statement provides no clue whether the computed value of this argument is in degrees or radians.

        I think it is ok for you to back to your teacher and ask if the actual dimensions for k are g-(deg/sec)^2 or g-(rad/sec)^2.

        Comment

        • whodgson
          Contributor
          • Jan 2007
          • 542

          #5
          Ummm.
          In this sort of motion (SHM) angular velocity is sort of synonymous with angular frequency ie w^2=k/m or w=sqrt(k/m)
          The units of k are N/m or kg/sec^2 so the units of k/m are kg/s^2/kg=s^-2
          When the sqrt of this is taken the unit of frequency is in rad/s.
          (recall f=w/2*pi = 1/2*pi * sqrt(k/m)
          But you are right in a sense because radian is not really a propper unit.
          Quite confusing really.

          Comment

          Working...