· sol2.nb 3. in[22]:= graph@10d out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps m = 10 in[23]:=...

15

Upload: others

Post on 06-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked
Page 2:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked
Page 3:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked
Page 4:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked
Page 5:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked
Page 6:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked
Page 7:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

ME201/MTH281/ME400/CHE400Assignment #2 SolutionsProblems 1, 3, 4 and the Challenge Problem

Problem 1We wish to express sin(q)cos3(q) as a linear combination of the functions sin(nq).

In[1]:= TrigReduce@Sin@qD Cos@qD^3D

Out[1]=1

8H2 Sin@2 qD + Sin@4 qDL

This is the same as we obtained by hand.

Problem 3ü (a)

In[2]:= fbas@x_D := 1 + x Abs@xD

In[3]:= f@x_D := fbas@Mod@x, 2 * L, -LDD

In[4]:= L = 1;

We check our definition by plotting f over [-3,3].In[5]:= Plot@f@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fHxL"<, AspectRatio -> 1 ê 3D

Out[5]=

-3 -2 -1 1 2 3x

0.5

1.0

1.5

2.0fHxL

ü (b)We check the values that we calculated earlier.

In[6]:= f@-1D

Out[6]= 0

Page 8:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

In[7]:= f@0D

Out[7]= 1

In[8]:= Limit@f@xD, x Ø 1, Direction Ø 1D

Out[8]= 2

Mathematica’s notation here is a bit awkward. Direction -> 1 means that you are moving to the right as you take thelimit, hence this is the limit as x-> 1-, the limit from the left. Similarly Direction -> -1 means approaching from theright.

In[9]:= Limit@f@xD, x Ø 1, Direction Ø -1D

Out[9]= 0

In[10]:= f@1D

Out[10]= 0

In[11]:= f@6D

Out[11]= 1

In[12]:= f@7D

Out[12]= 0

ü (d)We calculate the Fourier coefficients. We start with the sine coefficients.

In[13]:= coeffsin = H1 ê LL Integrate@f@xD Sin@Hn p xL ê LD, 8x, -L, L<D

Out[13]= -2 I2 - 2 Cos@n pD + n2 p2 Cos@n pD - 2 n p Sin@n pDM

n3 p3

This looks a little complicated because Mathematica does not know yet that n is an integer. We now simplify thisexpression under the assumption that n is an integer. We call the result b[n].

In[14]:= b@n_D = Simplify@coeffsin, n œ IntegersD

Out[14]= -2 I2 - 2 H-1Ln + H-1Ln n2 p2M

n3 p3

While this is a perfectly acceptable expression for b[n], we can get simpler forms by looking separately at the even nand odd n coefficients. For n even the coefficient is -2/(np), and for n odd it is 2/(n˛) - 8/(npL3 .Now the cosine coefficients.

In[15]:= a@0D = H1 ê 2 LL Integrate@f@xD, 8x, -L, L<D

Out[15]= 1

In[16]:= coeffcos = H1 ê LL Integrate@f@xD Cos@Hn p xL ê LD, 8x, -L, L<D

Out[16]=2 Sin@n pD

n p

In[17]:= a@n_D = Simplify@coeffcos, n œ IntegersD

Out[17]= 0

We can see from the graph that f[x] is essentially an odd function that has been shifted upward by a constant 1. Thusonly the constant term in the cosine part of the series is nonzero.

2 sol2.nb

Page 9:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

Problem 4ü (a)

The graph requested was already done in Problem 3, but we repeat it here for convenience.In[18]:= Plot@f@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fHxL"<, AspectRatio -> 1 ê 2D

Out[18]=

-3 -2 -1 1 2 3x

0.5

1.0

1.5

2.0fHxL

ü (b)We first define the Mth partial sum of the Fourier series, as a function of x and M.

In[19]:= ps@x_, M_D := a@0D + Sum@b@nD Sin@Hn p xL ê LD, 8n, 1, M<D

Finally we define a function graph[M] which produces a graph of the Mth partial sum, along with a graph of theoriginal function. We graph the original function in blue and the partial sum in red.

In[20]:= graph@M_D := Plot@8f@xD, ps@x, MD<, 8x, -3 L, 3 L<, PlotStyle Ø 8Blue, Red<,AxesLabel Ø 8"x", "f and ps"<, PlotLabel Ø Row@8"M = ", M<D, AspectRatio Ø 1 ê 2D

ü (c)We now construct the graphs for M = 5, 10, and 20.

In[21]:= graph@5D

Out[21]=

-3 -2 -1 1 2 3x

0.5

1.0

1.5

2.0

f and psM = 5

sol2.nb 3

Page 10:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

In[22]:= graph@10D

Out[22]=

-3 -2 -1 1 2 3x

0.5

1.0

1.5

2.0

f and psM = 10

In[23]:= graph@20D

Out[23]=

-3 -2 -1 1 2 3x

0.5

1.0

1.5

2.0

f and psM = 20

We are asked to say whether 20 terms gives a good representation of the original function. The problem withthat question is that we are given no criterion for "good." Clearly the partial sum of the series does follow the generalshape of the curve, but there are also obvious oscillations, which are especially large near the discontinuities. We can'treally answer the question until we know what kind of accuracy we require of our series representation. We wouldexpect to get a better representation with more terms. Let's try 50 terms.

In[24]:= graph@50D

Out[24]=

-3 -2 -1 1 2 3x

0.5

1.0

1.5

2.0

f and psM = 50

It now looks pretty good except near the discontinuities. The overshoot there is called the Gibbs phenomenon, and wewill look at it more closely in class very soon. The coefficients in this series drop off slowly with n -- like 1/n. So theterm for n = 100 is roughly 1 percent of the term for n = 1, and we would expect to have to use about 100 terms tohave the series generally agree to within 1 percent with the original function. As we will see when we study the Gibbsphenomenon, even when we take 100 terms there will be locations where the error is much larger than 1 percent.

4 sol2.nb

Page 11:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

Challenge ProblemFor each base function, we will plot the graph of the extended function, and in some of cases the graphs of the

extended derivatives. We will then use Mathematica to calculate the Fourier coefficients so that we can see howrapidly they decrease with n. Then we will attempt to relate the drop-off rate with the function behavior. We denotethe base function by fbas, and the periodically extended function by f. In all cases, the L value for the interval is 1:

In[25]:= L = 1;

ü (a)In[26]:= fbas@x_D := x

In[27]:= f@x_D := fbas@Mod@x, 2 * L, -LDD

In[28]:= Plot@f@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fHxL"<, AspectRatio -> 1 ê 2D

Out[28]=

-3 -2 -1 1 2 3x

-1.0

-0.5

0.5

1.0fHxL

Because the function is odd, only the sine coefficients will be non-zero.In[29]:= b@n_D = Simplify@HH1 ê LL Integrate@f@xD Sin@Hn p xL ê LD, 8x, -L, L<DL, n œ IntegersD

Out[29]= -2 H-1Ln

n p

We see that the rate of convergence here is 1/n.

ü (b)In[30]:= fbas@x_D := x2

In[31]:= f@x_D := fbas@Mod@x, 2 * L, -LDD

In[32]:= Plot@f@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fHxL"<, AspectRatio -> 1 ê 2D

Out[32]=

-3 -2 -1 1 2 3x

0.2

0.4

0.6

0.8

1.0fHxL

We will also plot the derivative of the extended function here. The derivative of the base function is 2x.In[33]:= fbasder@x_D := 2 x

sol2.nb 5

Page 12:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

In[34]:= fder@x_D := fbasder@Mod@x, 2 * L, -LDD

In[35]:= Plot@fder@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fderHxL"<, AspectRatio -> 1 ê 2D

Out[35]=

-3 -2 -1 1 2 3x

-2

-1

1

2fderHxL

Because the function is even, only the cosine coefficients will be non-zero.In[36]:= a@0D = H1 ê H2 LLL Integrate@f@xD, 8x, -L, L<D

Out[36]=1

3

In[37]:= a@n_D = Simplify@HH1 ê LL Integrate@f@xD Cos@Hn p xL ê LD, 8x, -L, L<DL, n œ IntegersD

Out[37]=4 H-1Ln

n2 p2

We see that the rate of convergence is 1/n2.

ü (c)In[38]:= fbas@x_D := x - x3

In[39]:= f@x_D := fbas@Mod@x, 2 * L, -LDD

In[40]:= Plot@f@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fHxL"<, AspectRatio -> 1 ê 2D

Out[40]=

-3 -2 -1 1 2 3x

-0.4

-0.2

0.2

0.4fHxL

We will also plot the derivative of the extended function here. The derivative of the base function is 1 - 3x2.

In[41]:= fbasder@x_D := 1 - 3 x2

In[42]:= fder@x_D := fbasder@Mod@x, 2 * L, -LDD

6 sol2.nb

Page 13:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

In[43]:= Plot@fder@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fderHxL"<, AspectRatio -> 1 ê 2D

Out[43]=-3 -2 -1 1 2 3

x

-2.0

-1.5

-1.0

-0.5

0.5

1.0fderHxL

We go one step further and plot the extended second derivative. The base second derivative is -6x. In[44]:= fbasder2@x_D := -6 x

In[45]:= fder2@x_D := fbasder2@Mod@x, 2 * L, -LDD

In[46]:= Plot@fder2@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fder2HxL"<, AspectRatio -> 1 ê 2D

Out[46]=

-3 -2 -1 1 2 3x

-6

-4

-2

2

4

6fder2HxL

The orginal base function is odd, so only the sine coefficients will be nonzero. In[47]:= b@n_D = Simplify@HH1 ê LL Integrate@f@xD Sin@Hn p xL ê LD, 8x, -L, L<DL, n œ IntegersD

Out[47]= -12 H-1Ln

n3 p3

We see here that the convergence is like 1/n3.

ü (d)In[48]:= fbas@x_D := 2 x2 - x4

In[49]:= f@x_D := fbas@Mod@x, 2 * L, -LDD

sol2.nb 7

Page 14:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

In[50]:= Plot@f@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fHxL"<, AspectRatio -> 1 ê 2D

Out[50]=

-3 -2 -1 1 2 3x

0.2

0.4

0.6

0.8

1.0fHxL

We will also plot the derivative of the extended function here. The derivative of the base function is 4x - 4x3.

In[51]:= fbasder@x_D := 4 x - 4 x3

In[52]:= fder@x_D := fbasder@Mod@x, 2 * L, -LDD

In[53]:= Plot@fder@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fderHxL"<, AspectRatio -> 1 ê 2D

Out[53]=

-3 -2 -1 1 2 3x

-1.5

-1.0

-0.5

0.5

1.0

1.5

fderHxL

We go one step further and plot the extended second derivative. The base second derivative is 4 - 12 x2

In[54]:= fbasder2@x_D := 4 - 12 x2

In[55]:= fder2@x_D := fbasder2@Mod@x, 2 * L, -LDD

In[56]:= Plot@fder2@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fder2HxL"<, AspectRatio -> 1 ê 2D

Out[56]=-3 -2 -1 1 2 3

x

-8

-6

-4

-2

2

4fder2HxL

One last step - a plot of the extended third derivative. The base third derivative is -36x.In[57]:= fbasder3@x_D := -36 x

In[58]:= fder3@x_D := fbasder3@Mod@x, 2 * L, -LDD

8 sol2.nb

Page 15:  · sol2.nb 3. In[22]:= graph@10D Out[22]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 10 In[23]:= graph@20D Out[23]=-3 -2 -1 1 2 3 x 0.5 1.0 1.5 2.0 f and ps M = 20 We are asked

In[59]:= Plot@fder3@xD, 8x, -3, 3<, AxesLabel Ø 8"x", "fder3HxL"<, AspectRatio -> 1 ê 2D

Out[59]=

-3 -2 -1 1 2 3x

-30

-20

-10

10

20

30

fder3HxL

Because the original base function is even, only the cosine coefficients will be non-zero.In[60]:= a@0D = H1 ê H2 LLL Integrate@f@xD, 8x, -L, L<D

Out[60]=7

15

In[61]:= a@n_D = Simplify@HH1 ê LL Integrate@f@xD Cos@Hn p xL ê LD, 8x, -L, L<DL, n œ IntegersD

Out[61]=48 H-1Ln

n4 p4

We see here that the convergence is like 1/n4.

ü DiscussionA careful look at the graphs reveals that the smoother the extended function, the more rapidly the Fourier series

converges. In the first example, the extended function was discontinuous and the convergence was like 1/n. In thesecond example the extended function was continuous, but the extended derivative was discontinuous, and the conver-gence was like 1/n2. In the third example, the extended function and first derivatives were continuous, but theextended second derivative was discontinuous, and the convergence was like 1/n3. In the fourth example, the extendedfunction, first and second derivatives were all continuous, but the extended third derivative was discontinuous, and theconvergence was like 1/n4. The rule which is emerging here is that if the extended kth derivative is the first one of thesequence of extended function and derivatives which has a discontinuity, the convergence of the series will be like1/nk+1. We will discuss this further in class.

sol2.nb 9