• Support PF! Buy your school textbooks, materials and every day products Here!

The graph of cosine(x) squared

  • Thread starter mjordan2nd
  • Start date
  • #1
178
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?
 

Answers and Replies

  • #2
33,265
4,965
I used the web site in your link, and graphed (y1 = ) (cos(x))2. To get the exponent, I used their x2 button.
 
  • #3
83
0
You're right, the graph is periodic over pi. What about the graph confuses you, exactly? Is your calculator set to radian mode?
 
  • #4
178
1
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.
 

Attachments

  • #5
178
1
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:
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.
 

Attachments

  • #6
33,265
4,965
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.
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.
 
  • #7
33,265
4,965
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:
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.
Can you be more specific about what you mean when you say you can't get a good fit?
 
  • #8
178
1
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:
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>
 

Attachments

  • #9
178
1
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.
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.
 

Related Threads on The graph of cosine(x) squared

  • Last Post
Replies
4
Views
1K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
3
Views
46K
  • Last Post
Replies
6
Views
9K
  • Last Post
Replies
3
Views
88K
Replies
17
Views
1K
Replies
1
Views
892
  • Last Post
Replies
2
Views
34K
  • Last Post
Replies
4
Views
2K
Replies
3
Views
1K
Top