Thread: College kid-need help w/ C program by tonight

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    19

    College kid-need help w/ C program by tonight

    Code:
    #include <stdio.h>
    #include <math.h>
    #include "drand.h"
    #define PI (4*atan(1))
    int main(void)
    {  
       double A, t, T, p, n, w, y, a, b, c;      
     
       A=drand()+1;
       T=((drand()+1)*10);
       w=(2*PI/T);
       p=drand()*2*(4*atan(1)); 
        
       for(t=0; t<=50; t++)
      {  n=(drand()*.6-.3)*A;      
         y=A*sin( w*t + p) + n;
        printf("%f %f \n\n", t, y);
     
      }
        return 0;
    }
    Now modify the program so that while generating the data it uses some method, of your choice, to produce a good estimate of the period from the data. The estimate must be based only on the y values, and could for example use a sliding window.
    Then, at the end, generate separate sine data using your sine function with w based on the estimated period, the original values of A and p, and no noise, to plot over the same range of t with points and lines.

    It orginally plots just points, now i need to plot a line in addition (along the points as much as possible).Thanks in advance and please keep it real simple if possible.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    How about "no"?


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    19
    You are rude
    You don't need to reply or look at my thread

  4. #4
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44
    How about you read THIS

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    19
    It says the entire homework, i already did part1 involving parrallel-series component reliability.
    Plus i already have part2 half done which is what i posted.
    So thanks for nothing.

  6. #6
    I Write C++ Apps, Sue Me.
    Join Date
    Feb 2006
    Location
    In My Computer
    Posts
    44
    Well with a title like: "College kid-need help w/ C program by tonight", Thats sure to get people to help you. People get annoyed when people ask others to do homework for them.

    If you tried asking:

    "I have this much code dont (put code here) but I am having trouble with this next part. I am trying to do whatever but don't understand whatever."

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You didn't do a damn thing. All you did is take the sample code to start the lesson, given to you by your instructor, and posted the entire homework problem, letter for letter. We're not as stupid as you'd like us to be.


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    19
    Wrong, why are you at these boards. Perhaps i worded it wrong, i needed help finding the period using a sliding window. You couldnt figure it out anyway.

    Write a program to produce 51 samples of a noisy sine wave based on the following formula, to be implemented as a C function with at least one argument t (i.e. the other variables can be either arguments or global variables, but the noise n must be added in the main program, not the function):

    y = A*sin( w*t + p) + n

    for t = 0, 1, 2, ..., 50 where the amplitude A, radian frequency w = 2*pi/T, phase shift p, and additive noise n are randomly generated in the following ranges:
    1.0 <= A <= 2.0
    10.0 <= T <= 20.0
    0.0 <= p <= 2*pi
    -0.3*A <= n <= 0.3*A

    Note that the random values for A, w, and p are generated just once, whereas random values for the noise n are generated for each sample.
    Program output must be double-spaced so it will plot with points and no lines.

    Now modify the program so that while generating the data it uses some method, of your choice, to produce a good estimate of the period from the data. The estimate must be based only on the y values, and could for example use a sliding window.

    Then, at the end, generate separate sine data using your sine function with w based on the estimated period, the original values of A and p, and no noise, to plot over the same range of t with points and lines.

  9. #9
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    >> You couldnt figure it out anyway.
    If our quzah couldn't figure that out I'd eat my own face.

    Seriously, we don't homework here. If you hadn't shoved the question in our faces without posting your attempt (if any) we would have helped you.

    You could say sorry now but I doubt it would make any difference judging by the impression you've already made.

    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> Perhaps i worded it wrong

    you might read this to begin with.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  11. #11
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    I'll do it for $10

  12. #12
    Registered User
    Join Date
    Jan 2006
    Location
    England, Norwich
    Posts
    38
    oh my god like that is so sad!

  13. #13
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Quote Originally Posted by Brian
    I'll do it for $10
    I'll do it for $9.50
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

  14. #14
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by kctrk4
    Wrong, why are you at these boards. Perhaps i worded it wrong, i needed help finding the period using a sliding window. You couldnt figure it out anyway.
    Why can't you do this yourself?
    There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.

  15. #15
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by eth0
    I'll do it for $9.50
    $9.30 and a block of cheese.
    Cheeeeeeeeese.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. Replies: 2
    Last Post: 11-29-2001, 02:07 AM