The graph of cosine(x) squared

  • Thread starter Thread starter mjordan2nd
  • Start date Start date
  • Tags Tags
    Graph
Click For Summary
SUMMARY

The discussion centers on the graph of cos²(x) and its unexpected behavior when plotted using different tools, including a TI-89 calculator and gnuplot. Users noted that while the graph should be periodic with a period of π, discrepancies arose due to the evaluation of the function over a large x interval (0-250). The conversation also delves into fitting data to Malus' law using gnuplot, where users encountered issues with fitting accuracy and the number of data points evaluated. The final consensus suggests that increasing the number of evaluated points in gnuplot may resolve the fitting issues.

PREREQUISITES
  • Understanding of trigonometric functions, specifically cos²(x)
  • Familiarity with gnuplot version 5.4 or later for data fitting
  • Basic knowledge of Malus' law in optics
  • Experience with data analysis and curve fitting techniques
NEXT STEPS
  • Learn how to adjust the sampling rate in gnuplot for better graph resolution
  • Explore advanced fitting techniques in gnuplot, including the use of different fitting algorithms
  • Study the implications of periodic functions in data analysis
  • Investigate the behavior of trigonometric functions over large domains in various graphing tools
USEFUL FOR

Mathematicians, physicists, data analysts, and anyone involved in optical experiments or data fitting using gnuplot.

mjordan2nd
Messages
173
Reaction score
1
This is not a homework problem per se. The graph of cos^{2}(x) 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?
 
Physics news on Phys.org
I used the website in your link, and graphed (y1 = ) (cos(x))2. To get the exponent, I used their x2 button.
 
You're right, the graph is periodic over pi. What about the graph confuses you, exactly? Is your calculator set to radian mode?
 
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

  • cos.jpg
    cos.jpg
    78 KB · Views: 758
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: \theta = \omega t + k. 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

mjordan2nd said:
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.
 
mjordan2nd said:
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: \theta = \omega t + k. 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?
 
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

  • Run2.jpg
    Run2.jpg
    49 KB · Views: 626
Mark44 said:
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.
 

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
2K
Replies
2
Views
3K
  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
6
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K