T05-GraphsCosine.mws

High School Modules > Trigonometry by Gregory A. Moore

     The Cosine Graph


An exploration of the many variations of the cosine graph.

[Directions : Execute the Code Resource section first. Although there will be no output immediately, these definitions are used later in this worksheet. Note that this worksheet is graphic intensive at times. If you experience problems it may be necessary to re-execute the "0. Code" section before executing each subsection. ]

 0. Code

>    restart; with(plots):

Warning, the name changecoords has been redefined

>    SolidPlot := proc(f,a,b)
local c;
c := COLOR(RGB, .4, .4, .8);
plot( f(x), x = a..b, filled = true, color=c, style=patchnogrid);
end:

>    SolidPlotRCol := proc(f,a,b)
local c;
c := COLOR(RGB, 5*evalf(rand()/10^13,2),
                5*evalf(rand()/10^13,2),
                5*evalf(rand()/10^13,2)  );
plot( f(x), x = a..b, filled = true, color=c, style=patchnogrid);
end:

>    SolidPlotCol := proc(f,a,b, COL)
local  box,i,n,x1,x2,xmid,delta,y1,y2,A,B, m,M,slope, concav, col:
plot( f(x), x = a..b, filled = true, color=COL, style=patchnogrid);
end:

>    CosPlot := proc(f)
local  A, B,G,start, endpt, speed, period, lift, amp, M,m :
M := maximize(f(x), x = 0..10); m := minimize(f(x), x = 0..10);
lift := (M + m)/2 ;
G := f(x) - lift;


if (nops(G) = 2) then
   amp := op(1,G);
   if (amp > 0) then start := solve(G = M - lift, x);
                else start := solve(G = m - lift, x); fi;
   speed := subs( x = 1, op(1, op(1, op(2,G))));
   period := 2*Pi/speed;
   amp := evalf(subs(x = start, G));
else
   amp := 1;
   start := evalf(solve(G = 1, x));
   speed := subs( x= 1, op(1,op(1,G)));
   period := evalf(2*Pi/speed);
fi;
endpt := start + period;

plots[display](
    SolidPlot( x->cos(x), 0, 2*Pi),
    plot( f(x), x = start..endpt, color = blue, thickness = 2),
    plot( { [[start,lift],[endpt,lift]],[[start,m],[endpt,m]],
            [[start,M],[endpt,M]] ,[[start,m],[start,M]] ,[[endpt,m],[endpt,M]]}  
           ,color = red, thickness = 1, linestyle = 2),
    plot( 0, x = 0..2*Pi)  );
end:


>   

>    SinCosTable := proc(n)
local i, A;
A := array( [seq( [ 2*i*Pi/n,           evalf(sin(2*i*Pi/n)),` `,
                    2*i*Pi/n - Pi/2,    evalf(cos(2*i*Pi/n - Pi/2)) ],   i = 0..n ) ]):
A[1,1] := theta:  A[1,2] := sin(theta): A[1,4] := theta- Pi/2: A[1,5] := cos(theta):

print(A);
end:

 1. The Basic Cosine Graph


Much like the sin(x), y = cos(x) is also a function of x and can be plotted. The values are different than those of the sine, of course.

>    cos( 3*Pi/7): % = evalf(%);

cos(3/7*Pi) = .2225209335

>    n := 12;
array( [seq( [ 2*i*Pi/n, evalf(cos(2*i*Pi/n)) ],   i = 1..n ) ]);

n := 12

matrix([[1/6*Pi, .8660254040], [1/3*Pi, .5000000000], [1/2*Pi, 0.], [2/3*Pi, -.5000000000], [5/6*Pi, -.8660254040], [Pi, -1.], [7/6*Pi, -.8660254040], [4/3*Pi, -.5000000000], [3/2*Pi, 0.], [5/3*Pi, .50...


This is the basic shape of the cosine graph

>    plot( cos(x), x = 0..2*Pi);

[Maple Plot]

>    SolidPlot( x-> cos(x) , 0, 2*Pi);

[Maple Plot]

>    display( [seq(  
  SolidPlotCol( x-> (k/16)*cos(x),0,2*Pi,
  COLOR(RGB, .35 - k/32, .35 - k/32, 1 - k/28 )),k = 1..16) ]);

[Maple Plot]

 2. Connection with Sine Graph


The sine and cosine graphs are closely related.

>    plot( {sin(x), cos(x)},x = 0..2*Pi, color = [red, blue], thickness = 2);
`Red is sine, Blue is cosine`;

[Maple Plot]

`Red is sine, Blue is cosine`

>    plot( {sin(x), cos(x)},x = 0..4*Pi, color = [red, blue], thickness = 2);

[Maple Plot]

 
They actually have the same shape - with a horizontal shift. You can think of the cosine graph following the sine graph in a sense. Notice that sine and cosine take the same values - at x values
Pi/2  apart.

>    sin(Pi/2); cos(0);

1

1


This is not only true for these two values, but for any two values of x.

>    SinCosTable(12);

matrix([[theta, sin(theta), ` `, theta-1/2*Pi, cos(theta)], [1/6*Pi, .5000000000, ` `, -1/3*Pi, .5000000000], [1/3*Pi, .8660254040, ` `, -1/6*Pi, .8660254040], [1/2*Pi, 1., ` `, 0, 1.], [2/3*Pi, .86602...


This explains the similarity in the graphs. Note that both the sine and cosine have the same period
2*Pi  and same amplitude (1). In a sense they are the same graph, starting from different values : sin starts at 0 while cosine starts at 1. If we think of it this way, then all of the factors which influence the sine graph will work the same way on the cosine.

 3. Amplitude


The amplitude of the cosine function is the height of its hill (and depth of its valley). For cos(x), the amplitude is 1.

>    display( plot(cos(x), x = 0..2*Pi, thickness = 2),
         plot( {[[0,0],[0,1]],[[2*Pi,0],[2*Pi,1]]} ,
         color = blue, linestyle = 2, thickness = 3),
         plot( [[Pi,0],[Pi,-1]], color = yellow, linestyle = 2, thickness = 3));

[Maple Plot]


A constant in front of the cos(x) function alters the amplitude just as the sine is altered.

>    f := x -> 1.5*cos(x);

f := proc (x) options operator, arrow; 1.5*cos(x) end proc

>    CosPlot( f );

[Maple Plot]



If the constant is positive but less than 1, the graph contracts toward the x axis.

>    f := x -> (3/4)*cos(x);

f := proc (x) options operator, arrow; 3/4*cos(x) end proc

>    CosPlot( f );

[Maple Plot]



If the constant is negative, the stretching factor is the same, but the cosine is flipped upside down.

>    f := x -> -3*cos(x);

f := proc (x) options operator, arrow; -3*cos(x) end proc

>    CosPlot( f );

[Maple Plot]

 4. Period & Frequency



The cosine graph is periodic - it repeats. Each section that repeats is called a "period." The fundamental "piece" that repeats has length of
2*Pi  - this is the period of the cosine.

The frequency is
1/(2*Pi)  - that is, the cos(x) function completes 1 cycle every "time" interval of 2*Pi  - or, another way to think of it is that the function completes 1/(2*Pi)  of a period every one unit of time.

>    display( plot( cos(x), x=0..6*Pi, color = blue),
         plot( cos(x), x=0..2*Pi, color = red, thickness = 5),
         plot( cos(x), x=2*Pi..4*Pi, color = green, thickness = 5),
         plot( cos(x), x=4*Pi..6*Pi, color = violet, thickness = 5) );

[Maple Plot]



If there is a constant times x inside of the cos(x) function, this affects the period and frequency. For example, cos(2x) will complete its cycles twice as fast - each one taking half as long. So the period of cos(2x) is
2*Pi/2 = Pi , and the frequency is 1 over that, or 1/Pi .

>    f := x -> cos(2*x);
CosPlot( f );

f := proc (x) options operator, arrow; cos(2*x) end proc

[Maple Plot]


Note that the horizonatal shifting is affected, but the amplitude remains 1. If the constant is less than one, the graph has a smaller frequency and a longer period.

>    f := x -> cos((1/2)*x);
CosPlot( f );

f := proc (x) options operator, arrow; cos(1/2*x) end proc

[Maple Plot]


If the constant is negative, the stretching factor is the same, but the cosine is flipped upside down.

>    f := x -> -.3*cos(x);

f := proc (x) options operator, arrow; -.3*cos(x) end proc

>    CosPlot( f );

[Maple Plot]


 

 5. Amplitude & Period Changes


The changes to period and amplitude can both operate indepently on a single cosine function. The period is a feature of the x coordiate and the amplitude is a feature of the y coordinate, so neither has any impact on the other.

>    f := x -> 5*cos(2*x);
`Half the period, but 5 times the amplitude`;
CosPlot(f);

f := proc (x) options operator, arrow; 5*cos(2*x) end proc

`Half the period, but 5 times the amplitude`

[Maple Plot]

>    f := x -> (1/4)*cos(.5*x);
`Twice the period, and 1/4 of the amplitude`;
CosPlot(f);

f := proc (x) options operator, arrow; 1/4*cos(.5*x) end proc

`Twice the period, and 1/4 of the amplitude`

[Maple Plot]

>    f := x -> 3*cos((1/2)*x);
`Twice the period, and 3 times the amplitude`;
CosPlot(f);

f := proc (x) options operator, arrow; 3*cos(1/2*x) end proc

`Twice the period, and 3 times the amplitude`

[Maple Plot]


 

 6.  Shifting & Lifting


In algebra we learn that y = f(x) and (y-b) = f(x-a), or y = f(x-a) + b, have the same graphs except the latter is shifted a units right, and b units up. The same concept applies to all other functions, including the cosine function.

>    plot( {x^2, (x-3)^2 + 4} , x = -3..6, y = 0..9);

[Maple Plot]

>    f := x -> cos(x - Pi/6) + 1 ;
CosPlot(f);

f := proc (x) options operator, arrow; cos(x-1/6*Pi)+1 end proc

[Maple Plot]

>    f := x -> cos(x -  Pi/2) - 2 ;
CosPlot(f);

f := proc (x) options operator, arrow; cos(x-1/2*Pi)-2 end proc

[Maple Plot]


 

 7.  Shifting/Lifting/Amplitude/Period


Here are some examples where all four transformation take place in the same function.

>    f := x -> 3*cos( 2*(x - Pi/12)) + 1;
`Amplitude = 3, speed = 2, period = Pi, vertical lift = 1, horizontal shift (phase shift) = Pi/12`;
CosPlot( f );

f := proc (x) options operator, arrow; 3*cos(2*x-1/6*Pi)+1 end proc

`Amplitude = 3, speed = 2, period = Pi, vertical lift = 1, horizontal shift (phase shift) = Pi/12`

[Maple Plot]

>    plot( f(x), x = 0.. 8*Pi);

[Maple Plot]


Another exmaple

>    f := x -> 5*cos( (1/2)*x + Pi) + 5;
CosPlot( f );

f := proc (x) options operator, arrow; 5*cos(1/2*x+Pi)+5 end proc

[Maple Plot]

>    plot( f(x), x = 0..20*Pi );

[Maple Plot]

 8. Composite Functions of Cosine

>    f := x -> abs(cos(x));
display(SolidPlot( x->cos(x), 0, 2*Pi),
        plot(f(x), x = 0..2*Pi, thickness = 2, color = red, thickness=3));

f := proc (x) options operator, arrow; abs(cos(x)) end proc

[Maple Plot]

>    f := x -> cos(x)^2;
display(SolidPlot( x->cos(x), 0, 2*Pi),plot(f(x), x = 0..2*Pi,
        color = red, thickness=3));

f := proc (x) options operator, arrow; cos(x)^2 end proc

[Maple Plot]

>    f := x -> cos(x)^3;
display(SolidPlot( x->cos(x), 0, 2*Pi),plot(f(x), x = 0..2*Pi,
        color = red, thickness=3));

f := proc (x) options operator, arrow; cos(x)^3 end proc

[Maple Plot]


We can look at families of similar cosine functions.  Here's
k/10*cos(x)  where k goes from 1 to 10.

>    k := 'k':
plot( { (k/10)*cos(x) $ k = 1..10}, x = 0..2*Pi);

[Maple Plot]

And cos(x)^k  for k=1..10

>    plot( { cos(x)^k $ k = 1..10}, x = 0..2*Pi);

[Maple Plot]

>    display( [ seq(  
  SolidPlotCol(  x-> sqrt(k)*cos(x)^(2*k),0,2*Pi,
  COLOR(RGB, .1 + k/25, .2 +  k/25, .4 +  k/25 )),k = 1..12),
  plot( [sqrt(k)*cos(x)^(2*k) $ k = 1..12],  x = 0..2*Pi,
         color = gray, axes = none)]);

[Maple Plot]

k+k/10*cos(k*x)  for k = 1..10

>    plot( { k + (k/10)*cos(k*x) $ k = 1..10}, x = 0..2*Pi);

[Maple Plot]

And Sum(cos((2*j+1)*x)/(2*j+1),j = 1 .. k)  for k = 1..10

>    display( [ seq(  
  SolidPlotCol(  x-> sum( cos((2*j+1)*x)/(2*j+1), j= 1..k),0,2*Pi,
  COLOR(RGB, .2 + k/25, .4 +  k/25, .1 +  k/25 )),k = 1..10),
  plot( {sum( cos((2*j+1)*x)/(2*j+1), j= 1..k) $ k = 1..10},
                    x = 0..2*Pi, color = wheat, axes = none)]);

[Maple Plot]

 9. Graphs of Sums of Sines and Cosines


The last example above was not merely a nice drawing.  If we add up sines and cosines with differing amplitudes and periods, we get some extremely useful periodic functions.  Physicists and engineers often use sums of sines and cosines to model periodic electrical impulses, such as those seen on a heart monitor.  These sums are called
Fourier series , which you will learn about if you study mathematics in university.

>    restart;

Here's perhaps the simplest kind of example: Sum(cos(k*x),k = 1 .. 15)

>    plot( sum( cos(k*x) , k = 1..15 ), x = 0..4*Pi);

[Maple Plot]

Sum(cos(k*x)/k,k = 1 .. 20)

>    plot( sum( cos(k*x)/k, k = 1..20), x = 0..4*Pi);

[Maple Plot]

Sum(sin(x*k)/k,k = 1 .. 20)

>    plot( sum( sin(x*k)/k, k = 1..20), x = 0..4*Pi);

[Maple Plot]

Sum(sin(x*k)/k-cos(x*k)/k,k = 1 .. 20)

>    plot( sum( sin(x*k)/k - cos(x*k)/k, k = 1..20), x = 0..4*Pi);

[Maple Plot]

Sum(sin(x*k)/k+(-1)^k*cos(x*k)/k,k = 1 .. 20)

>    plot( sum( sin(x*k)/k + ((-1)^k)*cos(x*k)/k, k = 1..20), x = 0..4*Pi);

[Maple Plot]

Sum(sin(k*x)/(k^2)+cos(k*x)/(k^2),k = 1 .. 10)

>    plot( sum( sin(x*k)/k^2 + cos(x*k)/k^2, k = 1..10), x = 0..4*Pi);

[Maple Plot]

Sum(sin(k^2*x)/(k^2)+(-1)^k*cos(k*x)/(k^4),k = 1 .. 10)

>    plot( sum( sin(x*k^2)/k^2 + ((-1)^k)*cos(x*k)/k^4, k = 1..10), x = 0..4*Pi);

[Maple Plot]

Sum(sin(2*k*x)/k-cos(x*(2*k+1))/k,k = 1 .. 50)

>    plot( sum( sin(x*(2*k))/k - cos(x*(2*k+1))/k, k = 1..50), x = 0..4*Pi);

[Maple Plot]

Sum(sin((3*k+1)*x)/((2*k+1)^2)-cos(3*k*x)/((2*k)^2),k = 1 .. 40)

>    plot( sum( sin(x*(3*k+1))/(2*k+1)^2 - cos(x*(3*k))/(2*k)^2, k = 1..40), x = 0..4*Pi);

[Maple Plot]

Sum(sin(3*k*x)/k+cos(3*k*x)/k,k = 1 .. 40)

>    plot( sum( sin(x*(3*k))/k + cos(x*(3*k))/k, k = 1..40), x = 0..4*Pi);

[Maple Plot]

 
       © 2002 Waterloo Maple Inc