1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The graph of cosine(x) squared

  1. Nov 10, 2011 #1
    This is not a homework problem per se. The graph of [tex]cos^{2}(x)[/tex] doesn't look like what I'd expect when I graph it here: http://my.hrw.com/math06_07/nsmedia/tools/Graph_Calculator/graphCalc.html, in gnuplot, or on my TI-89. I would expect it to be periodic with a period of pi. However, if you graph in radians over a domain of 0-250 you get something quite bizarre I think. What's stranger is that the website I have linked to and gnuplot have a pretty similar graph, but my calculator's graph looks completely different. Could anyone explain to me what's going on here?
     
  2. jcsd
  3. Nov 10, 2011 #2

    Mark44

    Staff: Mentor

    I used the web site in your link, and graphed (y1 = ) (cos(x))2. To get the exponent, I used their x2 button.
     
  4. Nov 10, 2011 #3
    You're right, the graph is periodic over pi. What about the graph confuses you, exactly? Is your calculator set to radian mode?
     
  5. Nov 10, 2011 #4
    It looks like this, which doesn't seem to be periodic over pi at all. When I do it on gnuplot I get the same result. On my calculator it looks like a wave-packer going through approximately two waves. So I'm trying to figure out why this is happening.
     

    Attached Files:

    • cos.jpg
      cos.jpg
      File size:
      78.7 KB
      Views:
      238
  6. Nov 10, 2011 #5
    Here's the real problem:

    I have a situation where a laser hits a linear polarizer, and a motorized analyzer. I assume the angle between the polarizer and the analyzer transmission axis is linear in time: [tex] \theta = \omega t + k[/tex]. I collect data for this as time progresses through a computer, and I want to fit it to Malus' law. Here's the code for gnuplot:

    Code (Text):

    set title 'Irradiance vs time'
    set xlabel "Seconds"
    set ylabel "Volts"
    w = 0.314535
    I = 0.636548
    k = 0-.62469
    FIT_LIMIT = 1e-99
    l(x) = I * cos(w * x + k)**2
    fit l(x) 'run2.dat' via w, I, k
    plot l(x), 'run2.dat'
    I will attempt to attach run2.dat.

    For some reason, I cannot seem to get a good fit. Any help would be appreciated.
     

    Attached Files:

    • Run2.txt
      Run2.txt
      File size:
      37.1 KB
      Views:
      106
  7. Nov 10, 2011 #6

    Mark44

    Staff: Mentor

    I don't see anything drastically wrong with this graph, other than it is very crude. The graphing program is probably evaluating the function at too few points (because of the large x interval), so it might not be showing what you think it should.
     
  8. Nov 10, 2011 #7

    Mark44

    Staff: Mentor

    Can you be more specific about what you mean when you say you can't get a good fit?
     
  9. Nov 10, 2011 #8
    I can show you. Based on the data and the code I have provided so far, gnuplot will do 5 iterations and no more. I have attached the plot for my data and my "fitted" function. It seems visually apparent that the "fit" is not "good", unless I am misinterpreting something horribly.

    In case it is helpful, the output gnuplot gives me is:

    Code (Text):

    Max. number of data points scaled up to: 3072


     Iteration 0
     WSSR        : 891.708           delta(WSSR)/WSSR   : 0
     delta(WSSR) : 0                 limit for stopping : 1e-099
     lambda   : 36.5893

    initial set of free parameter values

    w               = 0.314535
    I               = 0.636548
    k               = -0.62469
    /

     Iteration 1
     WSSR        : 852.627           delta(WSSR)/WSSR   : -0.0458357
     delta(WSSR) : -39.0808          limit for stopping : 1e-099
     lambda   : 3.65893

    resultant parameter values

    w               = 0.314876
    I               = 0.739896
    k               = -0.637262
    /

     Iteration 2
     WSSR        : 829.851           delta(WSSR)/WSSR   : -0.0274469
     delta(WSSR) : -22.7768          limit for stopping : 1e-099
     lambda   : 0.365893

    resultant parameter values

    w               = 0.315894
    I               = 0.889393
    k               = -0.764851
    /

     Iteration 3
     WSSR        : 829.244           delta(WSSR)/WSSR   : -0.000731871
     delta(WSSR) : -0.606899         limit for stopping : 1e-099
     lambda   : 0.0365893

    resultant parameter values

    w               = 0.316624
    I               = 0.893281
    k               = -0.858558
    ***********/

     Iteration 4
     WSSR        : 829.244           delta(WSSR)/WSSR   : -1.78226e-015
     delta(WSSR) : -1.47793e-012     limit for stopping : 1e-099
     lambda   : 3.65893e+008

    resultant parameter values

    w               = 0.316624
    I               = 0.893281
    k               = -0.858558
    ************
    After 5 iterations the fit converged.
    final sum of squares of residuals : 829.244
    rel. change during last iteration : 0

    degrees of freedom    (FIT_NDF)                        : 2438
    rms of residuals      (FIT_STDFIT) = sqrt(WSSR/ndf)    : 0.583209
    variance of residuals (reduced chisquare) = WSSR/ndf   : 0.340133

    Final set of parameters            Asymptotic Standard Error
    =======================            ==========================

    w               = 0.316624         +/- 0.0002631    (0.08311%)
    I               = 0.893281         +/- 0.01918      (2.147%)
    k               = -0.858558        +/- 0.03712      (4.323%)


    correlation matrix of the fit parameters:

                   w      I      k      
    w               1.000
    I               0.066  1.000
    k              -0.865 -0.056  1.000
    gnuplot>
     
     

    Attached Files:

    • Run2.jpg
      Run2.jpg
      File size:
      51.4 KB
      Views:
      181
  10. Nov 10, 2011 #9
    I see. So is it safe to say the software is not designed to handle such a large domain? Is this true for most computational programs in general for trig functions? My calculator gives me nonsense results as well. Even more interestingly, plotting cos(x) produces what visually appears to be nonsense on both the link above and my TI-89. I haven't tried it yet for gnuplot.

    If this is a problem of not enough x values being evaluated, do you know if there is a way I can change this in gnuplot? It would be nice to be able to get a fit for my data.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: The graph of cosine(x) squared
  1. Cosine graphs. (Replies: 4)

Loading...