>   

lab5.mws --- Trigonometric Integrals

>    restart;
with( plots ):

>   

Auxiliary Plotting Commands -- execute, do not modify!

>    FourierAnim := proc(f,n)
  local a, b, Fcos, Fsin, Pf, Psincos;
  a := (f,n) -> int( f*sin(n*x), x=-Pi..Pi )/Pi:
  b := (f,n) -> int( f*cos(n*x), x=-Pi..Pi )/Pi:
  Fsin := (f,n) -> add( a(f,m)*sin(m*x), m=1..n ):
  Fcos := (f,n) -> b(f,0)/2 + add( b(f,m)*cos(m*x), m=1..n ):
  Psincos := (f,n) -> plot( Fsin(f,n)+Fcos(f,n), x=-3*Pi..3*Pi, color=blue ):
  Pf := plot( f, x=-Pi..Pi ):
  return display( [seq(
                    display( [Psincos(f,m),Pf], title=sprintf("n=%a",m) ),
                    m=1..n )],
                  insequence=true ):
end proc:

Lab Overview

This lab is intended to replace a need to lecture on Section 8.2.

Our first example will be to compute the definite integrals integrals Int(sin(m*x)*sin(n*x),x = -Pi .. Pi) .

We will conclude the demonstration with the Fourier sine and cosine coefficients of a function. These computations will be illustrated with an example based on the "square wave function" defined to be -1 on ( -Pi , 0 ) and 1 on ( 0, Pi  ) and extended periodically with periodic 2*Pi .

The questions at the end of this lab require you to apply the two examples to slightly different situations. In particular, Questions 4, and 5 refer to the "sawtooth function". This is the function that is defined to be the periodic extension of the linear function f(x) = x  on [ -Pi , Pi  ]. The topics in this lab are the basis for a later lab on Fourier Series.

>   

Example 1 - Int(sin(m*x)*sin(n*x),x = -Pi .. Pi)  

The functions sin(n*x) , where n  = 1, 2, 3, ..., have the property that Int(sin(m*x)*sin(n*x),x = -Pi .. Pi) = PIECEWISE([0, m <> n],[Pi, m = n]) . In this example we will verify this claim.

Step 1: Develop Intuition with Graphical Animations

We begin by looking at the graph of the products sin(m*x)*sin(n*x)  for all combination of m  = 1, 2, .., 6 and n  = 1, 2, .., 6.

>    sm := sin(m*x);
sn := sin(n*x);

>    N := 6:
for m from 1 to N do
  q := [seq(
         plot( sm*sn, x=-Pi..Pi, view=[-Pi..Pi,-1..1],
               title=sprintf("Plot of %a*%a", sm, sn) ),
        n=1..N )]:
  P||m := display( q, insequence=true );
end do:
unassign( 'm', 'n' );

The above loop creates an animation, Pn , for each n  = 1, 2, .., 6. Now, we display these animations. In each animation, try to determine if the "area" under the curve is positive, negative, or zero. Hint: Look for symmetries.

>    P1;

>    P2;

>    P3;

>    P4;

>    P5;

>    P6;

>   

  • Do you see any patterns to these results?
  • How are the plots different when m = n  from what you see when m <> n ?

>   

Step 2: Analytic Evaluation with Maple

Next, we attempt to evaluate these definite integrals. To get started we use m , n  = 1, 2, 3 (please increase this to 10, and do not be concerned with the display of the 10x10 matrix). This time the results will be displayed in a matrix. To facilitate this, define a Maple function that accepts the values of m  and n  and returns the definite integral Int(sin(m*x)*sin(n*x),x = -Pi .. Pi) .

>    N := 3:
F := unapply( Int( sm*sn, x=-Pi..Pi ), (m,n) ):
M := Matrix( N, N, F, shape=symmetric );

Then ask Maple to evaluate the integrals

>    M = map( value, M );

>   

Step 3: Explicit Evaluation of the Definite Integrals

How did Maple do this? The answer involves using some trigonometric identities for products of sine functions.

>    Smn := sm*sn:
q1 := combine( Smn, trig ):
Smn = q1;

When each side of this equation is integrated with respect to x :

>    q2 := Int( q1, x ):
q3 := value( q2 ):
Int( Smn, x ) = q2;
`                           ` = q3;

Observe that this formula does not make sense when m = n  (or m = -n , but that is not an issue at this time). Because the sine function has value 0 for all integer multiples of Pi  (and because m-n  and m+n  are integers when m  and n  are integers), it is pretty clear that the value of the antiderivative at Pi  is 0 and the value at -Pi  is 0:

>    eval( q3, x=Pi ) assuming integer;

>    eval( q3, x=-Pi ) assuming integer;

Hence, Int(sin(m*x)*sin(n*x),x = -Pi .. Pi) = 0  whenever m  and n  are integers with m <> n .

To study the case when m = n  note that the product of sine functions simplifies to a square:

>    Smm := eval( Smn, n=m );

Here the appropriate trigonometric identity is

>    q4 := combine( Smm, trig ):
Smm = q4;

Once again, this expression is easily integrated with respect to x :

>    q5 := Int( q4, x ):
q6 := value( q5 ):
Int( Smm, x ) = q5;
`                     ` = q6 + C;

When this antiderivative is evaluated at Pi  and -Pi , the results are

>    q7 := eval( q6, x=Pi ) assuming integer:
q7;

and

>    q8 := eval( q6, x=-Pi ) assuming integer:
q8;

respectively, Therefore,

>    Int( Smm, x=-Pi..Pi ) = q7 - q8;

This verifies the result obtained automatically by Maple in the previous section and the general result:

  Int(sin(m*x)*sin(n*x),x = -Pi .. Pi) = PIECEWISE([0, m <> n],[Pi, m = n])  

>   

Example 2 - Fourier sine and cosine coefficients for the sign function

Let f be a function defined on the interval ( -Pi , Pi  ). The Fourier sine and cosine coefficients of f are defined to be

  a[n] = 1/Pi   Int(f(x)*sin(n*x),x = -Pi .. Pi) , for n  = 1, 2, 3, ....

  b[n] = 1/Pi   Int(f(x)*cos(n*x),x = -Pi .. Pi) , for n  = 0, 1, 2, ....

To illustrate this definition, let f be the ``sign function'':

  f(x) = PIECEWISE([1, 0 < x],[0, x = 0],[-1, x < 0])  .

In Maple, this function is implemented with the signum  command.

>    plot( signum(x), x=-Pi..Pi, discont=true, title="The sign function" );

>   

The Fourier sine coefficients for this function are defined in terms of the definite integral

>    q1 := Int( signum(x)*sin(n*x), x=-Pi..Pi )/Pi:
a[n] = q1;

>   

Step 1: Develop Intuition with Graphical Animations

Sine Coefficients

First, we look at the graph of the products signum(x)*sin(n*x)  for n  = 1, 2, .., 10.

>    sn := sin(n*x);

>    N := 10:
q := [seq(
        plot( signum(x)*sn, x=-Pi..Pi, view=[-Pi..Pi,-1..1],
              title=sprintf("Plot of %a", signum(x)*sn) ),
        n=1..N )]:
display( q, insequence=true );

  • Do you see a pattern to the area between the curve and the x -axis in these pictures?
  • What can you say by symmetry?
  • What is different about the symmetry for frames with n  even and n  odd?
  • Are these functions even or odd (or neither)? (How does that help you to evaluate the integrals?)

>   

Cosine Coefficients

Repeating this step for the cosine coefficients for n  = 0, 1, 2, .., 10:

>    cn := cos(n*x);

>    N := 10:
q := [seq(
        plot( signum(x)*cn, x=-Pi..Pi, view=[-Pi..Pi,-1..1], discont=true,
              title=sprintf("Plot of %a", signum(x)*cn) ),
        n=0..N )]:
display( q, insequence=true );

  • Do you see a pattern to the area between the curve and the x -axis in these pictures?
  • What can you say by symmetry?
  • What is different about the symmetry for frames with n  even and n  odd?
  • Are these functions even or odd (or neither)?

>   

Step 2: Analytic Evaluation with Maple

Next, we attempt to evaluate the definite integrals for the sine and cosine coefficients.

Sine Coefficients

To get started we use   n  = 1, 2, .., 10. This time the results will be displayed in a column vector. To facilitate this, define a Maple function that accepts a value for n  and returns the definite integral 1/Pi   Int(signum(x)*sin(n*x),x = -Pi .. Pi)

>    N := 10:
A := unapply( Int( signum(x)*sn, x=-Pi..Pi )/Pi, n ):
M := Matrix( N, 1, A );

To evaluate these integrals

>    M = map( value, M );

>   

Cosine Coefficients

Repeating these steps for the cosine coefficients:

>    N := 10:
B := unapply( Int( signum(x)*cn, x=-Pi..Pi )/Pi, n ):
M := Matrix( N, 1, B );

To evaluate these integrals

>    M = map( value, M );

Here the pattern is pretty obvious!

But, we still have to compute b[0] . Replace the %? in the following command to create a valid Maple command to compute b[0] . Then, execute both commands (in order) and find the value of b[0] .

>    B0 := %? ;

>    value( B0 );

>   

To conclude, we have discovered that

  a[n] = PIECEWISE([4/Pi/n, `n odd`],[0, `n even`]) ,         for all n  = 1, 2, 3, ....

  b[n] = 0 ,                                   for all n  = 0, 1, 2, ....

>   

Step 3: Explicit Evaluation of the Definite Integrals

To evaluate these integrals by hand, we would divide the interval ( -Pi , Pi  ) into two pieces ( -Pi , 0 ) and ( 0, Pi  ).

>   

Sine Coefficients

>    q2 := Int( signum(x)*sin(n*x), x=-Pi..Pi )/Pi:
A(n) = q2;
`               ` = value( q2 );

When we tell Maple that n (and any other variables in this expression) are integers:

>    value( q2 ) assuming integer;

To reduce this even further, look at the cases when n is odd and even separately:

>    value( q2 ) assuming odd;

>    value( q2 ) assuming even;

This is consistent with the results found in Steps 1 and 2.

>   

Cosine Coefficients

>    q3 := Int( signum(x)*cos(n*x), x=-Pi..Pi )/Pi:
B(n) = q3;
`` = value( q3 );

This, too, is consistent with the results found in Steps 1 and 2.

>   

Discussion

Why do we care about Fourier sine and cosine coefficients. While this will be studied in greater detail in a later lab, here is a preview.  Define the functions

  F[n](x) = Sum(a[m]*sin(m*x),m = 1 .. n)+b[0]/2+Sum(b[m]*cos(m*x),m = 1 .. n)  for n  = 1, 2, ....

Note that more and more coefficients are used in F[n]  as n increases. The following FourierAnim  command creates a 12-frame animation in which each frame consists of the signum function on [ -Pi , Pi  ] and F[n]  on [ -3*Pi , 3*Pi  ].

>    FourierAnim( signum(x), 12 );

Notice how the graphs of y = F[n](x)  have period 2*Pi  for all n . Moreover, as n  increases, the graphs of y = F[n](x)  provide better and better approximations to the signum function on [ -Pi , Pi  ].

>   

Lab Questions

1. Consider sin(m*x)*cos(n*x)  for integers m  and n . What is the value of Int(sin(m*x)*cos(n*x),x = -Pi .. Pi)  ?

2. Consider cos(m*x)*cos(n*x)  for integers m  and n . What is the value of   Int(cos(m*x)*cos(n*x),x = -Pi .. Pi)  ?

Hint: Lab Questions 1 and 2

>    cm := cos(m*x);
cn := cos(n*x);

Copy the Example 1 section (or selected Steps) here twice - once for Question 1 and once for Question 2. Use cm  and cn  defined above to replace appropriate occurrence of sm  and sn  in Example 1 and execute the appropriate commands.

>   

3. For the square wave, F[3](x) = 4/Pi*sin(x)+4/(3*Pi)*sin(3*x) . Why is F[4](x) = F[3](x) ?

4. The ``sawtooth function'' is f(x) = x , for -Pi  <= x  <= Pi , and  f is periodic with period 2*Pi , i.e., f(x+2*n*Pi) = f(x)  for -Pi  <= x  <= Pi  and n  an integer.

    Find the Fourier sine coefficient for the sawtooth function. Report both the general formula and the first five Fourier sine coefficients., a[n] , n  = 1, 2, .., 5.

Hint: Lab Question 4

To implement the sawtooth function in Maple, you may write either f  (after executing the following command) or, since all integration will be done on ( -Pi , Pi  ), simply type x  whenever you need to reference the function f.

>    f := x;

I  recommend copying the Example 2 section (or selected Steps from Example 1) and pasting it following this hint. Make the changes in the copy of Example 2.

>   

5. Use the FourierAnim  command to create an animation showing that the graphs of y = F[n](x)  converge to the sawtooth function. What is the smallest value of n  for which the graph of y = F[n](x)  has a maximum value larger than Pi ? Write this function F[n](x) .

Hint: Lab Question 5

Replace the %?  with an integer and look at the individual frames to answer this question. Do not make n  too small or too large.

>    FourierAnim( x, %? );

>   

6. [Essay Question] Let f(x) = Sum(a[n]*sin(n*x),n = 0 .. 3)  = a[1]*sin(x)+a[2]*sin(2*x)+a[3]*sin(3*x) . Explain why

  Int(f(x)^2,x = -Pi .. Pi) = Pi*Sum(a[n]^2,n = 1 .. 3)  = Pi*(a[1]^2+a[2]^2+a[3]^2) .

Note that all integrals that arise in this problem have been evaluated earlier in this lab. You can use the fact that Int(sin(m*x)*sin(n*x),x = -Pi .. Pi) = PIECEWISE([0, m <> n],[Pi, m = n])  without explanation.

>   

>