mathematics notebook

profileoveleberry
songyue_m210.zip

M210 Songyue.pages

preview.jpg

__MACOSX/._M210 Songyue.pages

M210-S16-class-5.pdf

M 210 More drawing in LATEX February 23, 2016

Arcs

An arc of radius r from point (p, q) with initial angle ϕ (phi) and final angle ψ (psi) is drawn in TikZ by the code

LATEX\draw (p,q) arc (phi:psi:r);

Note that TikZ does not require the center (a, b), which is often easier to determine that the arc’s initial point. Polar coordinates (relative to the arc’s center) can be used to express the initial point in terms of the arc’s center.

(a, b)

(p, q)

ϕ

ψ

r

p = a+ r cosϕ

q = b+ r sinϕ

In tikzpicture environment enter

\draw ({a+r*cos(phi)},{b+r*sin(phi)}) arc (phi:psi:r);

for the specific values of a, b, r, ϕ (phi) and ψ (psi).

LATEX

According to the TikZ’s manual, by default arcs are drawn in positive (counter-clockwise) direction, assuming initial angle ϕ to be smaller than ψ. However, I have been able to draw arcs in negative (clockwise) direction by choosing an initial angle larger than final angle.

Precise Label Positioning

The relative positions above, below, left, right, above left, above right, below left, and below right, provide positioning relative to the node (indicated by the dot) as illustrated in the following figures.

below

above left right

above left

below left

above right

below right

While it is possible to adjust the separation between label and node, it is not that easy to adjust the angle (the above provide label placement only for angles in multiples of 45◦). The following will work to place the label (that is its center) at the the indicated position: precise distance s at relative angle θ from the position of the node.

node

lab el

s

node coordinates (nx, ny) label coordinates (lx, ly)

θ

To place label at the above mentioned position use the code (where θ is theta degrees):

M 210 — February 23, 2016 page 44

LATEX\draw ({nx + s*cos(theta)}, {ny + s*sin(theta)}) node {label};

To rotate the label as in the above illustration, use code:

LATEX\draw ({nx + s*cos(theta)}, {ny + s*sin(theta)}) node {\rotatebox{theta}{label}};

Special Triangles

In trigonometry the triangles with degrees 45-45-90 and 30-60-90 provide exact values for the trigono- metric functions. It is quite easy to obtain the exact values of angles of 15 and 75 degrees from those of 30 degrees by half- and double-angle formulas and other trigonometric identities, however, these values can also be obtained from the following figure containing an equilateral triangle in a square with sides equal to 2.

1

The Regular Pentagon. Use trigonometric functions to draw a regular pentagon with its lower side along the line segment from (−1, 0) to (1, 0). Start by drawing this line segment.

LATEX\begin{center}

\begin{tikzpicture}[scale=2]

\draw[line width=1.2pt] (-1,0) -- (1,0);

\end{tikzpicture}

\end{center}

Extend the line segment on both sides by adding the following code.

LATEX\draw[line width=1.2pt] (1,0) -- ({1+2*cos(72)},{2*sin(72)});

\draw[line width=1.2pt] (-1,0) -- ({-1-2*cos(72)},{2*sin(72)});

Close the top of the pentagon, using angles denoted in the desired figure on the following page, by adding the following code.

LATEX\draw[line width=1.2pt]

({1+2*cos(72)},{2*sin(72)})--(0,{2*sin(72)+2*sin(36)})--({-1-2*cos(72)},{2*sin(72)});

Of course we can shorten the code by placing it all in one string using --cycle to close the pentagon’s path.

M 210 — February 23, 2016 page 45

Now add the following lines to provide a coordinate system.

LATEX\draw[gray] (-2,0)--(2,0);

\draw[gray] (0,-.25)--(0,3.35);

Add the second gray horizontal line.

Color and label the indicated angles. The yellow angle with the x-axis was obtained by the following code.

LATEX\draw[fill=yellow!50] (1,0)--(1.55,0) arc (0:72:0.55) -- cycle;

Use this as an example to draw the other angles.

108◦ 72◦

72◦

36◦

1

1/2 cos(72◦)

cos(36◦)

From the figure we see

cos(36◦) = 1

2 + cos(72◦).

Using the double angle formula for the cosine we have

cos(36◦) = 1

2 + 2 cos2(36◦)− 1,

which can be rewritten as 4 cos2(36◦)− 2 cos(36◦)− 1 = 0.

Because cos(36◦) > 0, with the help of the quadratic formula we conclude

cos(36◦) = 2 +

4− 4(4)(−1)

8 =

2 + √ 20

8 =

√ 5 + 1

4 .

It follows that

cos(72◦) =

√ 5− 1

4 .

See TikZercise 3 for an alternative derivation.

Construction Regular Pentagon.

Draw a unit circle, and let A and B be the points (0, 1) and (−1, 0), respectively.

M 210 — February 23, 2016 page 46

B O

A

Let C be the midpoint of OB. Then by the Pythagorean Theorem we have

AC2 = (1/2)2 + 12 = 5/4 =⇒ AC = 1

2

√ 5.

B O

A

C

Use AC as length for a pentagon, constructed as indicated in the following figure.

M 210 — February 23, 2016 page 47

B O

A

C

D

EF

Homework 4

TikZercises. Draw the following in a LATEX document using TikZ:

1. Draw the following proof of the Pythagorean Theorem.

a b

c

c

c

c

b a

b

a

a

b

a

a

a

b

b

b

M 210 — February 23, 2016 page 48

2. Draw the figure from page 44 with all angles labelled, and use the figure to find the exact values of cos, sin and tan at angles 15◦ and 75◦.

3. Draw a right-angled triangle with angles 72◦ and 18◦ whose side adjacent angle 72◦ has length 1 as shown in the adjacent figure.

To determine the exact value of hypotenuse x, first put two such triangles together as indicated in the following figure. Next, extend the above tri- angles’ base, mark a point E length x to the left of A along the base and complete a larger triangle BDE as shown in the following figure.

72◦

18◦

x

1A

B

C

72◦ 72◦

18◦ 18◦

x

1 1x A

B

C DE

Answer the following questions in your LATEX document:

(a) Find the missing angles ∠AEB and ∠ABE.

(b) Show that triangles DBE and ADB are similar.

(c) Using the similarity of triangles DBE and ADB, set up an equation for x and solve this equation.

(d) Find the missing sides and angles in the following two special right triangles, then draw them showing all sides and angles.

M 210 — February 23, 2016 page 49

72◦

18◦

1A C

B

E C

B

4. Draw the following figure with missing angles (indicated by arcs) and line segments filled in, and use this information to find identities for cos(α+ β) and sin(α+ β).

[Use optional argument rotate=ang in \draw for appropriate angle ang (in degrees) to rotate the line segments to denote a right angle.]

α

β

1

M 210 — February 23, 2016 page 50

5. On the legs of angle ∠ABC points P , Q, R and S are so that all five blue segments are equal (BP = PS = SR = RQ = BQ). Draw this figure and show that ∠ABC = 36◦.

C

AB R

S

P

Q

6. The following figure

1/2

1/4

1/8

1/16

1/32

1/64 1/128

1

256

shows that 1

2 +

1

4 +

1

8 +

1

16 +

1

32 +

1

64 +

1

128 +

1

256 + · · · = 1.

Using summation notation, the above states that

∞ ∑

k=1

1

2k = 1.

M 210 — February 23, 2016 page 51

7. Draw the following figure and typeset the derivation of the Law of Cosines following the figure.

θ

a c

b a cos θ b− a cos θ

a si n θ

The Pythagorean Theorem applied to the right-angled triangle results in

c2 = (a sin θ)2 + (b− a cos θ)2

= a2 sin2 θ + b2 + a2 cos2 θ − 2ab cos θ

= a2(cos2 θ + sin2 θ) + b2 − 2ab cos θ

= a2 + b2 − 2ab cosθ.

8. Draw the following figure.

θ θ

1

cos θ

sin θ

cos2 θ

sin2 θ

θ

co s θ sin

θ co s θ sin

θ

Behold:

cos 2θ = cos2 θ − sin2 θ,

sin 2θ = 2 cos θ sin θ.

9. Draw the following figure, and typeset the conclusions.

M 210 — February 23, 2016 page 52

A BC

P

θ

θ

1

Q

cos 2θ

sin 2θ

cos θ

cos θ

Considering right △APQ, it follows from the figure that

sin θ = sin 2θ

2 cos θ ,

cos θ = 1 + cos 2θ

2 cos θ ,

from which the identities

sin 2θ = 2 cos θ sin θ,

cos 2θ = 2 cos2 θ − 1.

follow easily.

Submit Homework 4 by 3:00pm on Tuesday, March 1, to Moodle.

Please put course, your last name, and homework number in the name of the file you submit (using a file name like M210-HW4-name).

__MACOSX/._M210-S16-class-5.pdf

M210-S16-class-7.pdf

M 210 Introduction to Mathematica March 8, 2016

Creator of Mathematica

British-born Stephen Wolfram received a Ph.D. in particle physics from the California Institute of Technology at age 20. In 1986Wolfram founded the Center for Complex Systems Research at the University of Illinois at Urbana-Champaign and started to develop the computer algebra system Mathematica, which was first released in 1988, when he left academia. In 1987 he co-founded a company called Wolfram Research which continues to develop and market the program.

Stephen Wolfram

Formatting Stylesheet from Format from the menu contains several stylesheets that can be used to change the appearance of a Mathematica Notebook. Title and sections header can be selected from Style from the menu. Clicking the plus (+) symbols following an output cell will bring up a window from which one can select Plain text or Other style text to include in the Notebook.

Notational Conventions During a Mathematica session input cells and output cells are labelled In[1], Out[1], In[2], Out[2], In[3], Out[3], etc. Input cells are evaluated by either the enter key or the shift-return key.

Built-in Mathematica commands and functions always begin with a capital letter. It is good practice to use lowercase letters for user defined objects. Function arguments are always enclosed by square brackets [ ]. Parentheses ( ) are used to group objects together, and to establish priority of opera- tions. Standard arithmetic operations are +, -, *, /, and ^. A space is interpreted as multiplication: xy is not the same as x*y, but the latter is the same as x y. Variable names cannot start with numbers, but otherwise numbers can occur, for example as subscripts. Greek letters can be entered and used, and something like ∆x can be a single variable.

Comments are delimited by (* and *).

The symbol % refers to the previous output, %% to the second-previous output, etc. It is also possible to refer to the output following Out[n] by using Out[n] or simply by %n. Output can be given in TraditionalForm, which is an attempt to match traditional mathematical notation. While it is possible to use TraditionalForm also for input, it is better to use StandardForm, which is the default for both input and output.

Calculator When he was ten years old, the calculating prodigy Truman Henry Safford (1836–1901) of Royalton, Vermont, was once asked to square, in his head, the number 365,365,365,365,365,365. His church leader reports, “He flew around the room like a top, pulled his pantaloons over the tops of his boots, bit his hands, rolled his eyes in their sockets, sometimes smiling and talking, and then seeming to be in agony, until in not more than a minute said he, 133,491,850,208,566,925,016,658,299,941,583,225”[1].

• Verify Safford’s answer using Mathematica.

Mathematical Constants Mathematica contains several mathematical constants such as Pi for π, E for Euler’s number e, I for the imaginary number i =

√ −1, and GoldenRatio for the golden ratio.

M 210 — March 8, 2016 page 63

Some of these constants can be displayed similarly to the usual notation, such as π, e, and i, by making use of the escape key Esc , as follows:

Traditional form Key sequence

π Esc p Esc

e Esc ee Esc

i Esc ii Esc

Likewise, superscripts and subscripts can be obtained combining the control key with ^ and -.

Traditional form Key sequence

x2 x Ctrl 6 2 >

x1 x Ctrl - 1 >

• Use Mathematica to evaluate eπi (make sure to leave space between the two symbols in the exponent; the answer should be −1).

The letters N and D cannot be used as names for user defined objects; they are built-in commands: the first for numerical approximation, the second for differentiation. Mathematica displays only six decimals by default when the numerical approximation N is applied. To get m digits of expr enter N[expr,m].

• Have Mathematica calculate 100 digits of π and of e.

• Which is larger πe or eπ? (The first computes to less than 23, the second to a number larger than 23.)

The StandardForm of Infinity can also be obtained using the escape key. Greek letters can be input using the escape key. The following table contains keyboards shortcuts for some common symbols.

Key sequence Result Full Name

Esc a Esc α \[Alpha]

Esc D Esc ∆ \[CapitalDelta]

Esc inf Esc ∞ \[Infinity]

Esc e Esc ǫ \[Epsilon]

Esc ce Esc ε \[CurlyEpsilon]

Esc deg Esc ◦ \[Degree]

Esc -> Esc → \[Rule]

Esc => Esc ⇒ \[Implies]

The golden ratio is often denoted by the Greek letter phi in honor of the Greek sculptor Phidias (ca 480 BC–430 BC).

• Use the letter ϕ for the golden ratio (can be input in Mathematica as Esc cphi Esc ), then simplify ϕ2 − ϕ.

In[1]:= ϕ = GoldenRatio

In[2]:= Simplify[ϕ2 − ϕ] In[3]:= Solve[x^2 - x == 1]

• What can you conclude about ϕ?

The golden ratio is the largest root of the above equation, which is the number

ϕ =

√ 5 + 1

2 .

This is the constant GoldenRatio in Mathematica (the other root of the above equation is the reciprocal of this constant).

M 210 — March 8, 2016 page 64

Symbolic Calculator If a variable var has been assigned a value this can be undone by using Clear[var] or, equivalently, inputting var =.. Once a variable has been assigned a value, Mathematica will substitute that value in all calculations of the session. For example, suppose we have calculated an expression to be 5− 3x+ x3, and now wish to evaluate this at x = 2. Far easier than to assign value 2 to variable x, then evaluate the expression, and finally clearing x, as indicated in the following sequence of code

Out[1]= 5 - 3 x + x^3

In[2]:= x=2

Out[2]= 2

In[3]:= %%

Out[3]= 7

In[4]:= x=.

would be to substitute the value of x into the given expression using /. followed by a value assignment to x using a right arrow as follows.

Out[1]= 5 - 3 x + x^3

In[2]:= % /. x → 2

Out[2]= 7

Substitution using /. makes it unnecessary to unclear the variable.

Lists Mathematica uses braces { and } for ordered lists, with the elements contained in the lists separated by commas.

If L denotes a list, then L [[k ]] gives its kth entry. The double square brackets are entered using the escape key: Esc [[ Esc gives [[ and ]] is obtained similarly. Note that the escaped double square brackets only serve an esthetic purpose (visually showing the components as functions of the list); using plain double brackets [[ and ]] will work as well (and saves key strokes).

In[1]:= L = {1, 8, 28, 56, 70, 56, 28, 8, 1}

Out[1]= {1, 8, 28, 56, 70, 56, 28, 8, 1}

In[2]:= L[[4]]

Out[2]= 56

The command Table can be used to create lists generated by formulas. For example

In[3]:= T = Table[i^2, {i, 10}]

Out[3]= {1, 4, 9, 16, 25, 36, 49, 64, 81, 100}

These lists can be manipulated with the various arithmetic operators.

• Investigate the result of adding and multiplying these lists, and squaring each of them.

Lists can be plotted using the ListPlot command:

In[4]:= ListPlot[L]

The built-in function Prime gives the prime numbers in order. We can generate a list of the first 1000 prime numbers:

In[5]:= Table[Prime[i], {i, 1000}]

M 210 — March 8, 2016 page 65

Sums and Series Evaluate some partial sums of the series

∑∞ n=1 1/n

2.

In[1]:= Sum[1/n2, {n, 1, 10}]

In[2]:= Sum[1/n2, {n, 1, ∞}]

Integral Integrals are evaluated similarly to sums. Evaluate the integral

∫ 1

0

x4(1− x)4

1 + x2 dx

by entering the following.

In[1]:= Integrate[x^4(1 - x)^4/(1 + x^2), {x, 0, 1}]

The answer is 22 7 − π. The above integral provides a means of estimating the error in the approxi-

mation π ≈ 22 7 ; see the next example.

Plotting We can plot the function in the above integral as follows.

In[1]:= Plot[x^4(1 - x)^4/(1 + x^2), {x, 0, 1}]

Locate the maximum of the above function, by setting its derivative equal to zero to find its critical point. Use this to estimate the integral, and thus obtain a bound for the exact answer of the integral obtained earlier. Following are the first steps of the above procedure.

In[2]:= D[x^4(1 - x)^4/(1 + x^2), x]

In[3]:= Solve[% == 0,x]

In[4]:= x^4 (1 - x)^4/(1 + x^2) /. %[[7]]

In[5]:= N[%]

The computed result of 0.00315543 gives an upperbound for the integral ∫ 1

0 x4(1−x)4

1+x2 dx, and thus

an upperbound for the error in the approximation π ≈ 22 7 .

Functions Functions are defined using delayed assignment := and indicating variable by following them with underscores.

In[1]:= f[x_]:=x^2

In[2]:= f[a+b+c] // Expand

Note that if Fcn is a function, expr // Fcn is short-hand for Fcn[expr].

In[3]:= (f[x+h]-f[x])/h // Simplify

M 210 — March 8, 2016 page 66

Animation Define the cycloid by

In[1]:= Cycloid[t_] := {t - Sin[t], 1 - Cos[t]}

This is a parametric curve that can be plotted using ParametricPlot:

In[2]:= ParametricPlot[Cycloid[t], {t, 0, 2 Pi}]

The following creates a simple animation.

Animate[Graphics[{

{EdgeForm[{Black, Thick}], Yellow, Disk[{t, 1}]},

Line[{{-1, 0}, {7, 0}}],

{Thick, Line[{{t, 1}, Cycloid[t]}]},

Disk[Cycloid[t], .075]}],

{t, 0, 2 Pi}]

Immediate versus Delayed Assignment An immediate assignment is made using =, while := is used for a delayed assignment. If we set variable x equal to 2 by using as input x=2, then variable x will be replaced by the number 2. The function Random with empty argument generates a random number between 0 and 1.

In[1]:= x= Random[]

In[2]:= {x, x, x}

Compare the output generated by the above code with that of

In[3]:= y := Random[]

In[4]:= {y, y, y}

An Example of Simplification Use Mathematica to simplify

( √ 6−

√ 2)(

√ 3 +

√ 2)− 2

( √ 6−

√ 2)(

√ 3 +

√ 2)

.

The command Simplify has little effect. We can use the command FullSimplify, which simplifies the given expression. Mathematica simplifies the expression to an expression containing nested radicals, which it does not simply any further. Help Mathematica to see if the expression can be further simplified to a number that involves 4

√ 2 and its reciprocal. [Suggestion: consider the square

of 21/4 − 2−1/4.]

In[1]:= q=((Sqrt[6]-Sqrt[2])(Sqrt[3]+Sqrt[2])-2)/Sqrt[(Sqrt[6]-Sqrt[2])(Sqrt[3]+Sqrt[2])]

In[2]:= Simplify[q]

In[3]:= FullSimplify[q]

M 210 — March 8, 2016 page 67

Using FullSimplify Mathematica arrives at the answer √

6 √ 2− 8 (Mathematica displays this in

different order, use TraditionalForm[%] to see identical output by Mathematica). Can this answer possibly be simplified? Let’s use Mathematica to calculate the square of 4

√ 2−1/ 4

√ 2. Using fractional

exponents we enter this in Mathematica as follows.

In[4]:= (2^(1/4)-2^(-1/4))^2 // Expand

The answer is reminiscent of the earlier output above. In fact, let’s have Mathematica compare the result of the last computation with the expression under the square root of its answer to the FullSimplify command:

In[5]:= %/(-8 + 6 Sqrt[2]) // Expand

Mathematica’s answer shows that twice the number 4 √ 2 − 1/ 4

√ 2 is

6 √ 2− 8, so that our origi-

nal expression (in Mathematica stored in variable q) would be equal to 2( 4 √ 2 − 1/ 4

√ 2). Let’s use

Mathematica to verify this:

In[6]:= FullSimplify[q - 2(2^(1/4)-2^(-1/4))]

The calculation confirms that we have found a simplified answer for the original fraction:

( √ 6−

√ 2)(

√ 3 +

√ 2)− 2

( √ 6−

√ 2)(

√ 3 +

√ 2)

= 2

(

4 √ 2− 1

4 √ 2

)

.

Using the rules of exponents we can rewrite the right-hand side of the above formula as

2 · 21/4 − 2 · 2−1/4 = 25/4 − 23/4.

Mathematica’s command FullSimplify can also be used to confirm this result:

In[7]:= FullSimplify[q - (2^(5/4)-2^(3/4))]

We have the following pretty simplification:

( √ 6−

√ 2)(

√ 3 +

√ 2)− 2

( √ 6−

√ 2)(

√ 3 +

√ 2)

= 25/4 − 23/4.

This example shows that while a computer algebra system (CAS) is very useful in simplifying complicated expressions, it may be necessary to provide intelligent coaching to get at expressions the CAS may not directly supply.

Special Trigonometric Values Use Mathematica to verify the following formula for the cosine (arrived at by several applications of double-angle formulas):

cos 4θ = 1− 8 sin2 θ + 8 sin4 θ. (1)

Simplify[Cos[4 \[Theta]] - 1 + 8 Sin[\[Theta]]^2 - 8 Sin[\[Theta]]^4]

Observing that 90◦ − 18◦ = 72◦ = 4(18◦), we easily see that sin(18◦) = cos 4(18◦), so by (1) x = sin(18◦) satisfies the equation

x = 1− 8x2 + 8x4. (2)

Use Mathematica to solve (2), and deduce from Mathematica’s answer the exact value of sin(18◦). Verify your answer using Mathematica.

There are several ways to solve the above polynomial equation. First it is easy to see that x = 1 is a solution so that x− 1 is a factor of the polynomial 8x4 − 8x2 − x+1, and we can divide to obtain the quotient:

M 210 — March 8, 2016 page 68

(8x^4-8x^2-x+1)/(x-1) // Simplify

The quotient is 8x3 + 8x2 − 1. We can has Mathematica evaluate this at −1/2 by entering:

8x^3+8x^2-1 /. x->-1/2

Since the result is 0 also x− (−1/2) = x+ 1/2 is a factor, so also 2x+ 1. Divide this out:

(8x^3+8x^2-1)/(2x+1) // Simplify

The resulting quotient is 4x2+2x−1, and x = sin(18◦) is a solution of the equation 4x2+2x−1 = 0.

Using the quadratic formula we get x = −1± √ 5

4 . Because sin(18◦) > 0 we conclude that

sin(18◦) =

√ 5− 1

4 .

An alternative is to factor the given polynomial 8x4 − 8x2 − x+ 1:

Factor[8x^3+8x^2-1]

Another alternative is to use Mathematica’s built-in solver:

Solve[8x^3+8x^2-1,x]

Using the subtraction formula for the sine and the exact values for sin(15◦) and cos(15◦) it is now easy to find an exact values for sin(3◦) and cos(3◦); see the first homework problem on page 136.

Another Example of Simplification

Use Mathematica to show that √

5(1 + 5 √ 4) =

5 √ 2 +

5 √ 8 +

5 √ 16− 1.

We enter the expressions into variables a and b in Mathematica:

a=Sqrt[5(1+Surd[4,5])]

b=Surd[2,5]+Surd[8,5]+Surd[16,5]-1

We can have Mathematica numerically approximate each of these quantities:

N[a]

N[b]

The above calculation does not establish the above formula (the calculation merely shows that the quantities are close to each other). To show the formula we need to use algebra. The following computes the square of quantity b:

b^2

Expand[%]

Since b is positive, validity of the formula is now established.

A Third Example of Simplification

Use Mathematica to simplify 3

2 + √ 5 +

3

2− √ 5. The numbers a =

3

2 + √ 5 and b =

3

2− √ 5

satisfy a3 = 2 + √ 5 and b3 = 2 −

√ 5, so a3 + b3 = 4. Before we enter these into Mathematica, lets

do some algebra:

M 210 — March 8, 2016 page 69

Clear[a,b]

(a+b)^3 // Expand

/. a^3+b^3->4

Factor waht remains after subtracting 4:

Factor[%-4]

Now observe that ab is easily computed, because (2 + √ 5)(2−

√ 5) = −1. So x = a+ b satisfies the

equation x3 = 4− 3x, that is x3 + 3x− 4 = 0. The calculation

Solve[x^3+3x-4==0]

shows that this cubic equation has one real real root, thus 3

2 + √ 5 +

3

2− √ 5 = 1, a result that

can also be obtained using Mathematica’s FullSimplify instead of Simplify (which does not do anything with this input).

Some Plotting Options The AspectRatio is by default set to the reciprocal of the golden ratio. Turning it to Automatic

will set the same aspect ratio along the x- and y-axis.

Test with the function y = √ 1− x2, −1 ≤ x ≤ 1.

Compare

Plot[Sqrt[1-x^2], {x, -1, 1}]

and

Plot[Sqrt[1-x^2], {x, -1, 1}, AspectRatio -> Automatic]

A list of functions can be plotted together, for example

Plot[{Sin[x], Sin[2x]}, {x, 0, 2 Pi}]

It is possible to have the plot display labels when the cursor is placed over one of the functions graphed. This is done using the function Tooltip, which takes two arguments: first the function, and second the label, entered between quotation marks.

Example:

Plot[{Tooltip[Sin[x], "sin x"], Tooltip[Sin[2 x], "sin 2x"]}, {x, 0, 2 Pi}]

The above plot has the same appearance as the one before, but see what happens when the cursor is moved over one of the graphs.

We can change the color and thickness of the graph by using the option PlotStyle, for example PlotStyle->{Thickness[0.005], Red}. If there is a list of functions, PlotStyle needs to be assigned to a list.

Plot[{Sin[x], Sin[2x]}, {x, 0, 2 Pi},

PlotStyle -> {{Thickness[0.005], Red}, {Thickness[0.0075], Blue}}]

We can add axes labels and ticks along the x-axis at π/2, π, 3π/2, 2π by adding AxesLabel and Ticks options:

Plot[{Sin[x], Sin[2x]}, {x, 0, 2 Pi},

PlotStyle -> {{Thickness[0.005], Red}, {Thickness[0.0075], Blue}}

AxesLabel -> {x, y}, Ticks -> {{Pi/2, Pi, 3 Pi/2, 2 Pi}, Automatic}]

M 210 — March 8, 2016 page 70

Note that Ticks is assigned a list of specification for the first and second axis. In the above example Automatic is chosen for the ticks along the second axis. Another possibility is None, which produces no ticks. Note that a list of values such as π/2, π, 3π/2, 2π is more easily specified using Range[a,b,c], where a and b are the first and last number and c denotes the increment. Enter the following in Mathematica:

Range[Pi/2, 2Pi, Pi/2]

We can set Frame to True to create a frame around the plot, and we can use FrameTicks to specify ticks along the edges of this frame. Note that FrameTicks takes a list of tick specifications for the pairs of vertical left and right edges, followed by the horizontal bottom and top edges.

Plot[{Sin[x], Sin[2 x]}, {x, 0, 2 Pi},

PlotStyle -> {{Thickness[0.005], Red}, {Thickness[0.0075], Blue}},

Frame -> True, Axes -> True,

FrameTicks -> {{Range[-1, 1, 1/2], None}, {Range[0, 2 Pi, Pi/6], None}}]

Gridlines can be added using GridLines. One option for GridLines is Automatic, but one can also specify the exact location of the gridlines, as in the following example, which also specifies the style of the gridlines as an ordered pair (replace one of the colors Green by some other other color to see the order).

Plot[{Sin[x], Sin[2 x]}, {x, 0, 2 Pi},

PlotStyle -> {{Thickness[0.005], Red}, {Thickness[0.0075], Blue}},

Frame -> True, Axes -> True,

FrameTicks -> {{Range[-1, 1, 1/2], None}, {Range[0, 2 Pi], Pi/6, None}},

GridLines -> {Range[0, 2 Pi, Pi/6], Range[-1, 1, 1/2]},

GridLinesStyle -> {{Thin, Green}, {Thin, Green}}]

There are a lot more options for Plot. Enter the following in Mathematica to see all option:

Options[Plot]

Help for a command is provided executing the command following ?, for example

? Plot

Piecewise Defined Functions Piecewise defined functions can be obtained using

Piecewise[{{expr1,cond1},{expr2,cond2},...,{exprn,condn}}], where expr j are expressions and cond j are conditions, for j = 1, 2, . . . , n.

Examples:

Plot[Piecewise[{{-x, x < 0}, {x, x >= 0}}], {x, -5, 5}]

Plot[Piecewise[{{Sqrt[-x], x < 0}, {Sqrt[x], x >= 0}}], {x, -5, 5}]

Let’s define a pulse function, and plot it:

ClearAll[f]

f[x_] := Piecewise[{{1 + x, -1 <= x < 0}, {1 - x, 0 <= x <= 1}}]

Plot[f[x], {x, -5, 5}]

The displayed plot is lousy at best. We need to help Mathematica with the range of this function, which is done using PlotRange.

Plot[f[x], {x, -5, 5}, PlotRange -> {0, 1}]

M 210 — March 8, 2016 page 71

The plot produced by the above is better, but the aspect ratio could be improved.

Plot[f[x], {x, -5, 5}, PlotRange -> {0, 1}, AspectRatio -> Automatic]

This is better, but the automatic ticks along the vertical axis are cluttered, so we remove them or specify them as follows.

Plot[f[x], {x, -5, 5}, PlotRange -> {0, 1}, AspectRatio -> Automatic,

Ticks -> {Automatic, {0, 1}}]

Now that we have a single pulse function, we can see what happens when we translate. In the same coordinate system as f draw the graphs of y = f(x+ 3) and y = f(x− 3), and identify these functions in the plot using Tooltip starting from:

Plot[{f[x], f[x + 3], f[x - 3]}, {x, -5, 5}, PlotRange -> {0, 1},

AspectRatio -> Automatic, Ticks -> {Automatic, None}]

Since the pulses do not overlap, the following function has the same graph:

Plot[f[x] + f[x + 3] + f[x - 3], {x, -5, 5}, PlotRange -> {0, 1},

AspectRatio -> Automatic, Ticks -> {Automatic, None}]

Sound Mathematica can also produce sound, which it treats analogous to graphics.

The following plays a pure tone with frequency 440 Hertz for one second.

In[1]:= Play[Sin[2 Pi 440 t], {t, 0, 1}]

• Play some pure tones with other frequencies.

Using the idea of the previous section we can create a function that when played by Mathematica (using Play) produces a complete octave of pure notes.

Using Data Sets Mathematica can call up massive data sets maintained by Wolfram Research, and these data sets can be used to define functions.

The following yields a list of CountryData.

In[4]:= CountryData["Properties"]

We can use this to display the flag and present population of countries, for example China.

In[5]:= Graphics[CountryData["China", "Flag"]]

In[6]:= CountryData["China", "Population"]

In[7]:= CountryData["China", "Area"]

M 210 — March 8, 2016 page 72

The following function defines the population density of a country, indicated by the variable c, and is used to calculate the population density of China.

In[8]:= popdensity[c ] := CountryData[c, "Population"]/CountryData[c, "Area"]

In[9]:= popdensity["China"]

The resulting answer is the population density in number of people per square kilometer.

References [1] Clifford A. Pickover, A Passion for Mathematics: Numbers, Puzzles, Madness, Religion, and the

Quest for Reality, John Wiley & Sons, 2005.

M 210 — March 8, 2016 page 73

Homework 6 This assignment consists of only Mathematica problems. Solutions of the problems should be given in a single Mathematica notebook displaying the requested formulas and graphics (please put your name, the assignment number and date on the top of your Mathematica notebook).

1. (a) Use Mathematica to find the exact values of sin 18◦, cos 18◦, sin 15◦, and cos 15◦.

(b) Use the formula sin(u − v) = sinu cos v − cosu sin v

to find an exact value for sin 3◦.

(c) Find an exact value for cos 3◦.

2. The Indian mathematician Ramanujan discovered many formulas for denesting radicals. Use Mathematica to verify the following formulas found by Ramanujan:

(a) 3

3 √ 2− 1 = 3

1/9− 3

2/9 + 3

4/9.

(b) 6

7 3 √ 20− 19 =

3

5

3 − 3

2

3 .

Srinivasa Ramanujan (1887–1920)(c)

3 √ 28− 3

√ 27 =

1

3

(

3 √ 98− 3

√ 28− 1

)

.

(d)

3 √ 5− 3

√ 4 =

1

3

(

3 √ 20 +

3 √ 2− 3

√ 25 )

.

3. Plot a graph of the function y = tan(sinx)− sin(tanx) over the interval [−π, π].

4. (a) Plot the graph of the function

f(x) = x(1− x)

1 + x2 , 0 ≤ x ≤ 1.

(b) Find exact expressions for the maximum value of f and where this value is obtained.

(c) Use derivative(s) to determine the graph’s concavity.

5. Use Mathematica to compute and rank the population densities of the following countries Argentina, Canada, China, Germany, Netherlands, US.

6. [Extra Credit] Construct a function that when played by Mathematica (using Play) produces a complete octave of pure notes.

Submit Homework 6 by 3:00pm on Tuesday, March 15, to Moodle.

Please put course, your last name, and homework number in the name of the file you submit (using a file name like M210-HW6-name.nb).

__MACOSX/._M210-S16-class-7.pdf

M210-S16-class-8.pdf

M 210 Plotting and Graphics in Mathematica March 15, 2016

We continue our discussion of Mathematica and cover more plotting and graphics. The last part of the handout contains more material on LATEX: cropping of pictures included with the graphicx

package, and some further formatting.

Contents

1 More Plotting in Mathematica 74

1.1 Plot Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

1.2 Changing Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

1.3 Points and Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

1.4 Tangent Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

1.5 Polar Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

1.6 Implicit Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

1.7 Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

2 Cropping Images, Image Conversion and Graphics Paths 80

2.1 Cropping Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

2.2 Graphics Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

3 Further Formatting of LATEX Documents 83

1 More Plotting in Mathematica

1.1 Plot Options

The following table lists several useful options for Plot.

Some options for Plot

option name default value description

AspectRatio 1/GoldenRatio ratio of width to height; set to Automatic to have equal units in horizontal and vertical direction

Axes True axes are drawn AxesLabel None place labels along axes. Use {"x","y"} to get

these labels Exclusions Automatic points to exclude LabelStyle {} style specification for labels (default empty). Filling None filling to insert under each curve FillingStyle Automatic style to use for filling PlotRange {Full,Automatic} range of variables to include. ColorFunction Automatic determines color of the surface PlotLabel None label for plot PlotLegends None legends for curves PlotStyle Automatic graphics directives for style of each surface ToolTip specifies an explicit tooltip label for a curve

Pages 75–80 discuss several examples. We will discuss further examples after first showing how to graph points and lines (so that these can be included in further examples).

1.2 Changing Directory

Mathematica saves and exports graphics files to it current directory. The command SetDirectory

can be used to change this directory to a more convenient folder. To change it to the subfolder mma of folder M210 on a flash drive labeled F, input the following into Mathematica:

M 210 — March 15, 2016 page 75

SetDirectory["F:\M210\mma"]

For Mac users, setting Mathematica’s current directory the subfolder mma of folder M210 on a flash drive named USB20FD, input the following into Mathematica:

SetDirectory["/Volumes/USB20FD/M210/mma/"]

Pictures saved or exported from Mathematica will then be stored in the subfolder mma of folder M210 on the flash drive.

1.3 Points and Lines

Points and Lines are plotted using the functions Point and Line with appropriate arguments in the Graphics command.

The code Graphics[Point[{1, 0}]] draws a point at (1, 0). There is no visible difference in output if the coordinates are changed, because Mathematica automatically centers the graphic at the only graphical element. More than one point can be plotted by listing the coordinates of the points. See what happens executing Graphics[Point[{{0, 0}, {1, 0}, {1/2, 1/2}}]]. The size of the point can be set by PointSize, which takes as possible arguments Large, Medium, Small, or numbers. Color can be specified by listing it as well, using capital letter, such as in Blue, Red, Yellow, LightGreen, etc. These size and color attributes can be applied to the list of points, as is the case in

Graphics[{PointSize[Large], Red, Point[{{0, 0}, {1, 0}, {1/2, 1/2}}]}]

If we want different size and colors for the points, we can specify this as in the following example:

Graphics[{{PointSize[Large], Red, Point[{0, 0}]},

{PointSize[Medium], Blue, Point[{1, 0}]},

{PointSize[0.02], Green, Point[{1/2, 1/2}]}}]

Line (segments) are specified by points between which they are to be drawn. These points are to be given in a list of ordered pairs, such as in the following example.

Graphics[Line[{{0, 0}, {2, 0}}]]

More segments can be included by including more points in the list, for example

Graphics[Line[{{0, 2}, {0, 0}, {2, 0}}]]

To draw coordinate axes we can use Arrow instead of Line, but we need of course have a pair of points as argument (since an arrow goes from a begin point to an end point):

Graphics[{Arrow[{{0, 0}, {2, 0}}], Arrow[{{0, 0}, {0, 2}}]}]

Line (or arrow) thickness and color can be specified similarly to how these attributes were added to points, for example:

Graphics[{Thick, Blue, Line[{{0, 2}, {0, 0}, {2, 0}}]}]

We will later discuss other primitive graphical objects, the above suffices to create plots that involve tangent lines.

1.4 Tangent Lines

Start by plotting the function y = sinx over the interval [0, 2π]. Define a to be equal to π/3. The point (a, sin a) can then be plotted together with the graph of the function, by placing the Plot for the graph and Graphics[Point[{a, Sin[a]}] together using the Show function as follows:

M 210 — March 15, 2016 page 76

a = Pi/3; Show[Plot[Sin[x], {x, 0, 2 Pi},

Ticks -> {Range[0, 2 Pi, Pi/2], Automatic}],

Graphics[{PointSize[0.01], Red, Point[{a, Sin[a]}]}]]

Note that the graphical elements are drawn in the order in which they are listed as argument of Show, and since we want to see the point on the graph, it is listed after the graph of the function.

Before we add the tangent line to the graph, let’s animate the above over a:

Manipulate[

Show[Plot[Sin[x], {x, 0, 2 Pi},

Ticks -> {Range[0, 2 Pi, Pi/2], Automatic}],

Graphics[{PointSize[0.015], Red, Point[{a, Sin[a]}]}]], {a, 0, 2 Pi}]

We can now add the tangent line by entering the function y = sin a+cos a(x−a) as a second function. Since we want to animate the resulting plot we put in a range specification (since the added line will cause Mathematica to change range for different values of a), and we color the tangent line (second plot) in the same color as the point parametrized by a. The following code should accomplish this:

a = Pi/3; Show[

Plot[{Sin[x], Sin[a] + Cos[a] (x - a)}, {x, 0, 2 Pi},

PlotRange -> {-2, 2},

Ticks -> {Range[0, 2 Pi, Pi/2], Automatic},

PlotStyle -> {{Thick, Blue}, {Thick, Red}}],

Graphics[{PointSize[0.015], Red, Point[{a, Sin[a]}]}]]

It is now easy to create an animation using Manipulate:

Manipulate[

Show[Plot[{Sin[x], Sin[a] + Cos[a] (x - a)}, {x, 0, 2 Pi},

PlotRange -> {-2, 2},

Ticks -> {Range[0, 2 Pi, Pi/2], Automatic},

PlotStyle -> {{Thick, Blue}, {Thick, Red}}],

Graphics[{PointSize[0.015], Red, Point[{a, Sin[a]}]}]], {a, 0, 2 Pi}]

We illustrate the use of several other options in the following example.

Example. Draw a graph of the function y = tanx over the interval [−π, π] using equal units in horizontal and vertical direction, nice tick-mark labels along the horizontal axis, and asymptotes drawn in a different color than the graph of the tangent.

Solution. Since the tangent is undefined at π/2 and −π/2, we set the option Exclusions to {-Pi/2, Pi/2}. We also set tick-marks at multiples of π/2 along the x-axis, and multiples of 2 along the y-axis, and reset AspectRatio to get equal units along both axes.

g=Plot[Tan[x], {x, -Pi, Pi},

Ticks -> {{-Pi, -Pi/2, Pi/2, Pi}, Range[-6, 6, 2]}, PlotRange->{-6.5, 6.5},

AspectRatio -> Automatic, Exclusions -> {-Pi/2, Pi/2}, AxesLabel -> {"x", "y"}]

The above does not show asymptotes, which we draw as lines. The asymptote x = π/2 can be drawn in the graph as the line connecting the points (π/2,−6.5) and (π/2, 6.5), in Mathematica obtained by applying the function Line to the list {{Pi/2, -6.5}, {Pi/2, 6.5}}. We set the color to red, and place everything in Graphics:

a1 = Graphics[{Red, Line[{{Pi/2, -6.5}, {Pi/2, 6.5}}]}]

The other asymptote is defined similarly (or the above argument for Line can be adjusted to include the other pair of coordinates), and we can use Show to display all graphics objects in one coordinate system:

a2 = Graphics[{Red, Line[{{-Pi/2, -6.5}, {-Pi/2, 6.5}}]}];

Show[g, a1, a2]

M 210 — March 15, 2016 page 77

Example: Draw the graphs of the sine and cosine functions in one coordinate system using nice tick-marks and a legend to identify the graphs.

Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi},

Ticks -> {Range[Pi/6, 2 Pi, Pi/6], {-1, 1}},

PlotLegends -> "Expressions"]

1.5 Polar Curves

Recall the meaning of polar coordinates: θ is the angle between the segment connecting (x, y) and the origin, and r the distance between (x, y) and the origin. The following equations relate polar coordinates (r; θ) to rectangular coordinates:

x = r cos θ,

y = r sin θ.

If r is non-negative, then r = √

x2 + y2; in case r is negative, the above equations are still valid, with appropriate interpretation for angle θ.

b

r

θ

The polar curve r = f(θ), θ1 ≤ θ ≤ θ2 is plotted by PolarPlot[f[θ], {θ, θ1, θ2}].

Example: Plot r = 2 cos θ, r = 1 + 2 cos θ, r = 2 + 2 cos θ, and r = 3 + 2 cos θ.

To plot these curves, use the code:

PolarPlot[2 Cos[Theta], {Theta, 0, 2 Pi}]

PolarPlot[1 + 2 Cos[Theta], {Theta, 0, 2 Pi}]

PolarPlot[2 + 2 Cos[Theta], {Theta, 0, 2 Pi}]

PolarPlot[3 + 2 Cos[Theta], {Theta, 0, 2 Pi}]

We can create an animation that includes the above graphs by enclosing PolarPlot by a Manipulate:

Try the following:

Manipulate[PolarPlot[a + 2 Cos[Theta], {Theta, 0, 2 Pi}], {a, 0, 3}]

The above animation does not look good, because the plotted scale is varying with the polar curves. We can fix this including PlotRange to specify a single range for all the plots as follows:

Manipulate[

PolarPlot[a + 2 Cos[Theta], {Theta, 0, 2 Pi},

PlotRange -> {{-1, 5}, {-4, 4}}, AxesLabel -> {"x","y"}], {a, 0, 3}]

We can also change the constant 2 in the family of polar curves by b:

Manipulate[

PolarPlot[a + b Cos[Theta], {Theta, 0, 2 Pi},

PlotRange -> {{-1, 5}, {-4, 4}}, AxesLabel -> {"x","y"}], {a, 0, 3}, {b, 1, 3}]

1.6 Implicit Curves

Example 1: Graph the equation x4 − x2 + y2 = 0.

The equation x4 − x2 + y2 = 0 is easily solved for y: y2 = x2 − x4, so there are two solutions: y =

√ x2 − x4 and y = −

√ x2 − x4. We can graph these using Plot.

Plot[{Sqrt[x^2-x^4],-Sqrt[x^2-x^4]}, {x,-1,1}]

M 210 — March 15, 2016 page 78

The two graphs are plotted in different colors, which can be changed to give the graph of the equation a uniform appearance. We can also use ContourPlot to graph the equation.

ContourPlot[x^4-x^2+y^2==0, {x, -1, 1}, {y, -1, 1}]

We can improve the graph by taking a larger value for PlotPoints (which has default value equal to 25), reduce the range on the y variable, and change the color to blue drawn with absolute thickness of 1.5 pts, using the following code:

ContourPlot[x^4 - x^2 + y^2 == 0, {x, -1, 1}, {y, -1/2, 1/2},

ContourStyle -> {Blue, AbsoluteThickness[1.5]}, PlotPoints -> 50,

AspectRatio -> Automatic]

Example 2: We can graph the equation sinx sin y = 1/4, for 0 ≤ x ≤ π and 0 ≤ y ≤ π, by using the following code, which sets the frame ticks at specified numbers:

ContourPlot[Sin[x] Sin[y] == 1/4, {x, 0, Pi}, {y, 0, Pi},

FrameTicks -> {{{0, Pi/2, Pi}, None}, {{0, Pi/2, Pi}, None}}]

Now, let’s see if we can draw the above graph using Plot. We would need to solve the given equation sinx sin y = 1/4 for y. Note that the given equation implies

sin y = 1

4 sinx .

In case y ≤ π/2 we can take the inverse and obtain

y = arcsin

(

1

4 sinx

)

.

We can graph this by entering the code:

Plot[ArcSin[1/(4 Sin[x])], {x, 0, Pi}, AspectRatio -> Automatic,

PlotRange -> {0, Pi}, Frame -> True,

FrameTicks -> {{{0, Pi/2, Pi}, None}, {{0, Pi/2, Pi}, None}}]

In case π/2 < y ≤ π, we know that 0 ≤ π − y < π/2, and since

sin(π − y) = 1

4 sinx ,

we obtain

π − y = arcsin

(

1

4 sinx

)

,

thus

y = π − arcsin

(

1

4 sinx

)

.

We can graph the two parts by entering the code:

Plot[{ArcSin[1/(4 Sin[x])], \[Pi] - ArcSin[1/(4 Sin[x])]},

{x, 0, Pi}, AspectRatio -> Automatic, PlotRange -> {0, Pi},

Frame -> True,

FrameTicks -> {{{0, Pi/2, Pi}, None}, {{0, Pi/2, Pi}, None}},

PlotStyle -> Blue]

We can obtain the graph of sinx sin y = a, for 0 ≤ x ≤ π and 0 ≤ y ≤ π, by replacing 1/4 above by a, and can do this for varying a using a manipulate.

Compare the two codes below:

Manipulate[ContourPlot[Sin[x] Sin[y] == a, {x, 0, Pi}, {y, 0, Pi},

FrameTicks -> {{{0, Pi/2, Pi}, None}, {{0, Pi/2, Pi}, None}}],

{a, 0, 1}]

M 210 — March 15, 2016 page 79

and

Manipulate[Plot[{ArcSin[a/Sin[x]], \[Pi] - ArcSin[a/Sin[x]]},

{x, 0, Pi}, AspectRatio -> Automatic, PlotRange -> {0, Pi},

Frame -> True,

FrameTicks -> {{{0, Pi/2, Pi}, None}, {{0, Pi/2, Pi}, None}},

PlotStyle -> Blue], {a, 0, 1}]

As a gets closer to 0, the contour curves sinx sin y = a appear to become more circular. How can we explain this?

Note that

sinx sin y

= cos (π

2 − x

)

cos (π

2 − y

)

=

(

1− 1

2

2 − x

)2

+ 1

24

2 − x

)4

− · · · )(

1− 1

2

2 − y

)2

+ 1

24

2 − y

)4

− · · · )

= 1− 1

2

2 − x

)2

− 1

2

2 − y

)2

+ higher order terms.

If a is close to 1, both x and y are close to π/2 so that the higher order terms are much smaller than the terms of order 2, and the equation sinx sin y = a is approximated by

1− 1

2

2 − x

)2

− 1

2

2 − y

)2

= a,

which is equivalent to equation

2 − x

)2

+ (π

2 − y

)2

= 2(1− a),

the circle centered at (π/2, π/2) of radius √

2(1− a).

A circle centered at (a, b) of radius r can be drawn using Circle[{a,b},r] inside the function Graphics. The following code draws a circle centered at (π/2, π/2) of radius 5/4.

Graphics[Circle[{Pi/2, Pi/2}, 5/4]]

We can color the circle red by listing Red together with the circle as an ordered pair using braces (for lists) as follows

Graphics[{Red,Circle[{Pi/2, Pi/2}, 5/4]}]

Next, we can use the function Show to combine the two graphics objects: the graph of the contour curve and the above circle:

Show[

Plot[{ArcSin[1/(4 Sin[x])], Pi - ArcSin[1/(4 Sin[x])]},

{x, 0, Pi}, AspectRatio -> Automatic, PlotRange -> {0, Pi},

Frame -> True,

FrameTicks -> {{{0, Pi/2, Pi}, None}, {{0, Pi/2, Pi}, None}},

PlotStyle -> Blue],

Graphics[{Red, Circle[{Pi/2, Pi/2}, 5/4]}]]

Finally, replacing both occurrences of 1/(4 Sin[x]) by a/Sin[x], and changing the circle’s radius to Sqrt[2(1-a)], we can manipulate over variable a to see the limiting behavior of contour curves:

Manipulate[Show[

Plot[{ArcSin[a/Sin[x]], Pi - ArcSin[a/Sin[x]]}, {x, 0, Pi},

AspectRatio -> Automatic, PlotRange -> {0, Pi},

Frame -> True,

FrameTicks -> {{{0, Pi/2, Pi}, None}, {{0, Pi/2, Pi}, None}},

PlotStyle -> Blue],

Graphics[{Red, Circle[{Pi/2, Pi/2}, Sqrt[2 (1 - a)]]}]], {a, 0, 1}]

M 210 — March 15, 2016 page 80

1.7 Regions

Regions can be plotted using RegionPlot.

Example:

RegionPlot[Sin[x] Sin[y] > 1/4, {x, 0, Pi}, {y, 0, Pi},

BoundaryStyle -> Thick, PlotStyle -> Yellow,

FrameTicks -> {{Range[0, Pi, Pi/6], None}, {Range[0, Pi, Pi/6], None}}]

2 Cropping Images, Image Conversion and Graphics Paths

2.1 Cropping Images

The bounding box of a figure is specified by the coordinates of its the lower left and upper right corners with respect to a customary coordinate system; if the coordinates of the lower left corner of a figure are llx and lly, respectively, and the coordinates of the upper right corner of a figure are urx and ury, respectively, (all coordinates in pixels) the bounding box is specified as llx lly urx ury; see figure 1. The graphicx package finds and uses the bounding box of each image it includes in a LATEX document. An error message that an image’s bounding box cannot be found usually means that the image is not in the path LATEX searches while compiling the document. Any graphic placed in the same folder as the LATEX source file should be found by LATEX. It is possible to place graphic files in other folders, but then LATEX needs to be told the folder’s path. Any number of folder’s with graphics can be added to LATEX’s search, so that images created with certain software packages can be kept in the directories these programs search for their files (usually the same location new files such as saved images are written).

x

y

(llx,lly)

(urx,ury)

Figure 1: The bounding box of a figure

Images can be loaded and converted to PDF format using Mathematica as follows:

url="http://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Stephen_Wolfram_PR.jpg/420

px-Stephen_Wolfram_PR.jpg"

Import[url]

Export["wolfram.pdf",%]

The above code has Mathematica load the image and convert it to an PDF graphic that can be used to include into a LATEX document, using the graphicx package. The above image was used on the first page of last week’s handout, where Wolfram’s portrait appeared cropped. This was done by using options in the LATEX document, rather than taking the time to crop the image in other software.

M 210 — March 15, 2016 page 81

The full picture of the above photo (which is 420 by 600 pixels):

Stephen Wolfram

The following code, used in last week’s handout, illustrates the use of cropping1:

LATEX\begin{center}

\includegraphics[bb=290 460 395 570,clip]{wolfram} %(size 420x600)

\\

Stephen Wolfram

\end{center}

1In this optional argument delimited by square brackets the bounding box for cropping is specified, and clip tells

graphicx to crop according to the specified coordinates, which were found by trial and error.

M 210 — March 15, 2016 page 82

The resulting image appeared on the first page of the handout of March 8:

Stephen Wolfram

2.2 Graphics Path

When a LATEX document is compiled, LATEX should be able to find any graphics file placed in the same folder as the source file. However, when working with lots of graphics files from various sources it can be convenient to organize these graphics files in folders away from the LATEX source file, and tell LATEX where to find the pictures. This is possible using graphicspath which takes as argument the path to these folders.2 I used the following graphics path in the preamble of this document:

LATEX\graphicspath{{/Users/karel/Documents/Dropbox/mma-pics/}}

Notice that the folder from which the graphics files are to be read, in the above case the folder mma-pics) is to be ended with a forward slash, and the path name is to be enclosed in braces { and }. More than one graphics path can be specified and relative paths are allowed. For example, if you want to use graphics files in the sub-directory (sub-folder) pics of the directory that contains your LATEX document, then this can be included in the graphics path as follows:

LATEX\graphicspath{

{/Users/karel/Documents/Dropbox/mma-pics/}

{./pics/}

}

Further graphic paths can be added, even to folders on mounted drives such as flash drives. The following adds a graphics path to the folder M210 on a USB drive called USB20FD:

LATEX\graphicspath{

{/Users/karel/Documents/Dropbox/mma-pics/}

{./pics/}

{/Volumes/USB20FD/M210/}

}

Unfortunately, subfolders of folders in LATEX’s graphics path are not searched, and need to be given their own graphics path.

For Macintosh users these graphics paths can be combined to make the flash drive work on a Mac or PC, since LATEX ignores graphics paths it cannot find:

LATEX\graphicspath{

{/Volumes/USB20FD/M210/mma-pics/}

{F:/M210/mma-pics/}

}

2I have separate folders for graphics generated by different programs on my computer, and graphics created with

these programs are saved to these folders. Placing each of these folders in the graphics path of a LATEX document,

no graphics files need to be moved for LATEX to find them. By placing these folders in my Dropbox, and syncing my

Dropbox between computers, I can create graphics files from either my desktop or laptop working in these programs

and compile LATEX documents using these graphics files on either computer without any difficulty.

M 210 — March 15, 2016 page 83

3 Further Formatting of LATEX Documents

Following is a brief discussion of some formatting not yet discussed. This may be useful in using LATEX to write articles, and these notes assume the documentclass article (start the source file with \documentclass{article}).

Sections are created using \section{my section}. Starred versions (\section*{my section}) are not labelled. A table of contents to be included at the beginning of the document can be created using \tableofcontents. Note it requires two compilations before this table of contents is typeset with the most current labels and page numbers.

An abstract can be added by using the abstract environment: place the contents of this ab- stract between \begin{abstract} and \end{abstract} at the beginning of the document (after \begin{document}).

A bibliography can be added at the end of the document using the environment thebibliography, which takes as argument the number of digits of the total number of biographical entries (so that LATEX can figure spacing for the labels it uses for this list of entries). Place bibliographical items be- tween \begin{thebibliography}{n} and \end{thebibliography} using \bibitem for each entry, followed by a short unique label for this entry in braces: for example:

LATEX\begin{thebibliography}{1}

\bibitem{AUT:sol}A.U. Thor, \textsl{The Book with all Solutions},

Know-it All Press, Utopia, 2015.

\end{thebibliography}

It is then possible to refer to bibliographical entries using \cite and \bibitem’s label of the par- ticular entry. For example, for a proof of Fermat’s Theorem that does fit the margin, see [1] (typeset as \cite{AUT:sol}). Often it is not useful to cite an entire book, so we can use \cite’s optional argument to be more specific: for the above mentioned proof see [1, p. 123] (typeset as \cite[p.~123]{AUT:sol}, the optional argument in square brackets).

Hyper references can be included in a document (including its bibliography) if the hyperref package is loaded: in the document’s preamble include something like the following (used in this document):

LATEX\usepackage[colorlinks=true,urlcolor=blue]{hyperref}

We can then include hyper links in our document, using \href{url}{web page}. An example is the following link with lots of material on the history of math: http://www-history.mcs.st-and.ac.uk/ or MacTutor History of Mathematics archive typeset as

LATEX\href{http://www-history.mcs.st-and.ac.uk/}{http://www-history.mcs.st-and.ac.uk/}

or

\href{http://www-history.mcs.st-and.ac.uk/}{MacTutor History of Mathematics archive}

We can also include the above website in the bibliography by adding the following entry:

LATEX\bibitem{MacTutor} MacTutor’s history website

\href{http://www-history.mcs.st-and.ac.uk/}{http://www-history.mcs.st-and.ac.uk/}.

References

[1] A.U. Thor, The Book with all Solutions, Know-it All Press, Utopia, 2015.

[2] MacTutor’s history website http://www-history.mcs.st-and.ac.uk/.

M 210 — March 15, 2016 page 84

Homework 7 This assignment consists of only Mathematica problems. Solutions of the problems should be given in a single Mathematica notebook displaying the requested formulas and graphics.

1. Plot the function y = t− sin t and its first and second derivative in one coordinate system over the interval [0, 6π]. Label the coordinate axes, using tick-marks of multiples of π along the hor- izontal axis, and use PlotLegends to place a legend on the plot (taking value "Expressions").

2. Draw the graph of y = secx in a coordinate system over the interval [−π, π], displaying asymptotes in different colors than the graph of the function.

3. Draw the graph of y = cotx in a coordinate system over the interval [−π/2, 5π/2], displaying asymptotes in different colors than the graph of the function.

4. Animate the functions f(x) = a sin(bx+ c)+ d for parameters a, b, c, and d. Choose the range and the intervals for the parameters so that all graphs display in one window. Briefly describe how changing the parameters effects the graph of f .

5. Create an animation of moving tangent lines to the graph of y = x3 − 4x2 + 2x + 3 in an appropriately chosen window.

6. Plot the region of points (x, y) with −π ≤ x ≤ π and −π ≤ y ≤ π, where tan(x) tan(y) > 1/4.

Submit Homework 7 by 3:00pm on Tuesday, March 22, to Moodle.

Please put course, your last name, and homework number in the name of the file you submit (using a file name like M210-HW7-name.nb).

  • More Plotting in Mathematica
    • Plot Options
    • Changing Directory
    • Points and Lines
    • Tangent Lines
    • Polar Curves
    • Implicit Curves
    • Regions
  • Cropping Images, Image Conversion and Graphics Paths
    • Cropping Images
    • Graphics Path
  • Further Formatting of LaTeX Documents

__MACOSX/._M210-S16-class-8.pdf

M210-S16-class-9.pdf

M 210 Graphics in Mathematica March 22, 2016

We discuss creating graphics in more detail. We will want to discuss enough to create animations built from graphics. We also discuss how to determine the envelopes of some of the families of lines and circles drawn earlier.

Contents

1 Graphics in Mathematica 85

1.1 Drawing in Mathematica . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

1.2 Envelopes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87

1.3 Cycloid Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

1 Graphics in Mathematica

1.1 Drawing in Mathematica

Relevant commands:

Mathematica input Result Graphics[primitives,options] represents a two-dimensional graphical image

Graphing Primitives

Arrow[{{x1,y1},{x2,y2}}] arrow from point (x1, y1) to point (x2, y2) Circle[{cx,cy},r] circle centered at (cx, xy) with radius r Disk[{cx,cy},r] filled disk centered at (cx, xy) with radius r Point Takes as argument a single point or a list of points Polygon Takes as argument list of points; the resulting poly-

gon is filled Plot

Line Takes as argument a pair of points or a list of points Rectangle[{xmin,ymin},{xmax,ymax}] rectangle with sides parallel to coordinate axes be-

tween the points (xmin, ymin) and (xmax, ymax) Text[expr,{cx,cy}] text expr centered at point (cx, cy)

Some Graphing Directives

Arrowheads[size] size is a number or one of Tiny, Small, Medium, Large

Background background color specification Dashing line dashing specification EdgeForm edge drawing specification FaceForm face drawing specification Opacity[a] opacity a PointSize[size] size is a number or one of Tiny, Small, Medium,

Large

Thickness[w] line thickness specification

M 210 — March 22, 2016 page 86

Example 1. Draw the regular pentagon shown in the adjacent figure.

Draw the pentagon using the following list of points:

In[1]:= α = 2π/5 In[2]:= Table[{Cos[k α], Sin[k α]}, {k, 0, 4}]

In[3]:= Graphics[{Circle[{0,0},1], Point[%]}]

In[4]:= p := Table[{Cos[k α + π/10], Sin[k α + π/10]}, {k, 0, 4}]

With the pentagon p defined above, connect every other point:

In[5]:= Graphics[{Circle[{0,0},1],Line[{p[[1]],p[[2]],p[[3]],p[[4]],p[[5]],p[[1]]}]}]

Source: www.spikedmath.com

Example 2. Draw the five pointed star shown in the adjacent figure.

With the pentagon p defined above, connect every other point:

In[1]:= Graphics[{Circle[{0,0},1],Line[{p[[1]],p[[3]],p[[5]],p[[2]],p[[4]],p[[1]]}]}]

We take a particular r to draw an example of a star, though it will not create the above perfect star; we postpone finding the exact value for r that will draw the above perfect star. It is then easy to determine all inner vertices of the star, and define a list of all vertices of the star as follows. The code

M 210 — March 22, 2016 page 87

In[2]:= r = 1/2;

In[3]:= q = r Table[{Cos[3π/10 + 2 k π/5], Sin[3π/10 + 2 k π/5]}, {k, 0, 4}]

In[4]:= star = {p[[1]],q[[1]],p[[2]],q[[2]],p[[3]],q[[3]],p[[4]],q[[4]],p[[5]],q[[5]],p[[1]]}

In[5]:= Graphics[{Thick, Line[star]}]

results in the following imperfect star

In fact, the following creates an animation that shows the stars for varying values of r:

In[6]:= Clear[r]

In[7]:= Manipulate[

q = r Table[{Cos[3π/10 + 2 k π/5], Sin[3π/10 + 2 k π/5]}, {k, 0, 4}];

star = {p[[1]],q[[1]],p[[2]],q[[2]],p[[3]],q[[3]],p[[4]],q[[4]],p[[5]],q[[5]],p[[1]]};

Graphics[{Thick, Line[star]}], {r, 0, 1}]

1.2 Envelopes

An envelope of a set of lines (or circles) is a curve tangent to all of the lines (or circles).

Example 3. Find the envelope of the line segments between (cos θ, 0) and (0, sin θ) for all possible angles θ.

Recall that the command Lines is defined on pairs of points (themselves specified as pairs using braces instead of the usual parentheses). So to draw the line connecting the points (cos θ, 0) and (0, sin θ) for a particular value of θ, say θ = 35◦, we can enter the following.

In[1]:= θ = 35◦;

Graphics[{

Arrow[{{-1.2, 0}, {1.2, 0}}],

Arrow[{{0, -1.2}, {0, 1.2}}],

Line[{{Cos[θ], 0}, {0, Sin[θ]}}] }]

The command Line extends to lists of pairs of points, and we have seen that Table provides an easy way to generate such lists. So if we want to draw a family of lines parametrized in a regular way, then we can make use of Table, which we can simply put inside the Line command. Suppose we want to draw the lines connecting points (cos θ, 0) and (0, sin θ) for the angles in the first quadrant that are multiples of 10◦, then we can do so as follows.

M 210 — March 22, 2016 page 88

In[2]:= Graphics[{

Arrow[{{-1.2, 0}, {1.2, 0}}],

Arrow[{{0, -1.2}, {0, 1.2}}],

Line[Table[{{Cos[θ], 0}, {0, Sin[θ]}}, {θ, 0, 90◦, 10◦}]]

}]

We can visualize what happens with more line segments by creating a demonstration using Manipulate. Instead of degrees, let’s use radians, and draw the lines finer as more are drawn. Also, there is no reason to restrict to the first quadrant: if θ increases in steps of 2π/n, then after n increases we get back to where we started.

In[3]:= Manipulate[Graphics[{

Arrow[{{-1.2, 0}, {1.2, 0}}],

Arrow[{{0, -1.2}, {0, 1.2}}],

{Thickness[0.1/n], Line[Table[{{Cos[θ],0}, {0,Sin[θ]}}, {θ,0,2 π,2 π/n}]]} }], {n, 24, 200, 4}]

Note that the control for the variable n goes from 24 to 200 in increments of 4, and that with increasing n the thickness of the lines decreases so that we get a nicer image. If we want to start n at a different value than its lowest bound, say at 40, we can do so by replacing n in the code by {n,40}. Do we further want a label, for example, “number of lines”, we add that as a third element in this list. Finally, if we want the value of n displayed next to its slider, we add Appearance → "Labeled"

after the limit specifications of n.

For example,

In[4]:= Manipulate[Graphics[{

Arrow[{{-1.2, 0}, {1.2, 0}}],

Arrow[{{0, -1.2}, {0, 1.2}}],

{Thickness[0.1/n], Line[Table[{{Cos[θ],0}, {0,Sin[θ]}}, {θ,0,2 π,2 π/n}]]} }], {{n, 40, "number of lines"}, 24, 200, 4, Appearance → "Labeled"}]

The limiting figure as n tends to ∞ is called the envelope of this family of line segments. It is the curve under which a ladder of unit length can still slide along the vertical wall to the floor (or, alternatively, can be carried around the corner, touching two perpendicular walls). We can use calculus to find the shape of the above envelope. Since θ varies, we need to find the maximum of the functions that give the lines:

y = sin θ − (tan θ)x

We can do so by setting the derivative with respect to θ equal to 0, then solving the resulting equation. First remember to clear variable θ (which we earlier gave a specific value).

In[5]:= Clear[θ] In[6]:= D[Sin[θ] - (Tan[θ]) x, θ] In[7]:= Solve[% == 0, x]

The solution is x = sin3 θ. Substitute this into the above equation to obtain y. We can use Mathematica to simplify the expression:

In[8]:= Sin[θ] - (Tan[θ]) x /. → %

In[9]:= Simplify[%]

We see that y = cos3 θ. Now check to see that this curve is indeed the envelope.

In[10]:= ParametricPlot[{Sin[t]^3, Cos[t]^3}, {t, 0, 2 π}]

We can actually plot it together with the envelope using Show to combine the graphic corresponding to n = 200, together with the plot above parametric curve:

M 210 — March 22, 2016 page 89

In[11]:= n = 200;

Show[

Graphics[{

Arrow[{{-1.2, 0}, {1.2, 0}}],

Arrow[{{0, -1.2}, {0, 1.2}}],

{Thickness[0.1/n], Line[Table[{{Cos[θ],0}, {0,Sin[θ]}}, {θ,0,2 π,2 π/n}]]} }],

ParametricPlot[{Cos[t]^3, Sin[t]^3}, {t,0,2 π}, PlotStyle→ {Thick,Red}]

]

The above code creates the following picture (line thickness not translated correctly in the picture in this document):

Finally, we can display the moving line inside the envelope:

In[12]:= Animate[Show[

Graphics[{

Arrow[{{-1.2, 0}, {1.2, 0}}],

Arrow[{{0, -1.2}, {0, 1.2}}]

}],

ParametricPlot[{Cos[t]^3, Sin[t]^3}, {t,0,2 π}, PlotStyle→ {Thick, Red}],

Graphics[{Thick, Blue, Line[{{Cos[θ], 0}, {0, Sin[θ]}}]}] ], {θ, 0, 2 π}]

Example 4. For positive number c, let Lc be the line with equation y = (2/c) + (1− 1/c2)x. Find the envelope for this family of lines.

Let’s first draw these lines. The code

In[1]:= Show[

Plot[Table[2/c + (1 - 1/c^2) x, {c, .1, 12, .05}], {x, -5, 5},

PlotRange -> Automatic, PlotStyle -> Thickness[0.0015]],

Plot[Table[2/c + (1 - 1/c^2) x, {c, -12, -.1, .05}], {x, -5, 5},

PlotRange -> Automatic, PlotStyle -> Thickness[0.0015]]

]

results in the following picture

M 210 — March 22, 2016 page 90

-4 -2 2 4

-10

-5

5

10

in which the envelope is apparent. Next, find the critical point(s) by differentiating y with respect to parameter c, and solving where this derivative is 0.

In[2]:= ClearAll[c, x]; y := 2/c + (1 - 1/c^2) x

In[3]:= D[y, c]

In[4]:= Solve[% == 0, x]

In[5]:= y /. %

In[6]:= Simplify[%]

It is readily seen that x and y satisfy the equation y = x+ 1/x. Plot this with above lines:

In[7]:= Show[

Plot[Table[2/c + (1 - 1/c^2) x, {c, .1, 12, .05}], {x, -5, 5},

PlotRange -> Automatic, PlotStyle -> Thickness[0.0015]],

Plot[Table[2/c + (1 - 1/c^2) x, {c, -12, -.1, .05}], {x, -5, 5},

PlotRange -> Automatic, PlotStyle -> Thickness[0.0015]],

Plot[x + 1/x, {x, -5, 5}, PlotStyle -> {Red, Thick}, Exclusions -> {0}]

]

which produces the following picture.

-4 -2 2 4

-10

-5

5

10

M 210 — March 22, 2016 page 91

1.3 Cycloid Curves

Example 5. The cycloid was first studied by Marin Mersenne (1588–1648). The cycloid is defined to be the locus of a fixed point on a circle rolling along a line. In the following figure a circle of positive radius a is rolled along the x-axis. One point on the rolling circle as well as the spoke to the circle’s center is drawn at various instances.

Marin Mersenne (1588–1648)

The following figure displays the circle after it has rolled a distance at.

at

(x, y)

p

q θ

The length of the arc on the circle between the vertical radius and the radius with endpoint (x, y) is equal to at. If angle θ is as indicated in the figure, then the above arc has angle θ + π/2, thus length (θ + π/2)a. It follows that (θ + π/2)a = at, which implies t = θ + π/2. Thus θ = t − π/2, so the indicated lengths are p = a cos(t− π/2) = a sin t, and q = a sin(t− π/2) = −a cos t. We have x = at− p = a(t− sin t) and y = a+ q = a(1− cos t). Thus parametric equations for the cycloid are

x = a(t− sin t) and y = a(1− cos t).

We can now animate the cycloid in Mathematica:

Manipulate[

Graphics[{

{EdgeForm[{Black, Thick}], Yellow, Disk[{t, 1}]},

Line[{{-1, 0}, {7.25, 0}}],

{Thick, Line[{{t, 1}, {t - Sin[t], 1 - Cos[t]}}]},

{PointSize[0.015], Red, Point[{t - Sin[t], 1 - Cos[t]}]}

}], {t, 0, 2 Pi}]

M 210 — March 22, 2016 page 92

We can add the trace of the red point:

Manipulate[

Show[{

Graphics[{

{EdgeForm[{Black, Thick}], Yellow, Disk[{t, 1}]},

Line[{{-1, 0}, {7.25, 0}}],

{Thick, Line[{{t, 1}, {t - Sin[t], 1 - Cos[t]}}]},

{PointSize[0.015], Red, Point[{t - Sin[t], 1 - Cos[t]}]}

}],

ParametricPlot[{u - Sin[u], 1 - Cos[u]}, {u, 0, t}, PlotStyle -> Red]

}],{t, -10^-6, 2 Pi}]

The following example is a variation on the cycloid.

Example 6. Instead of rolling a disk along a straight line, roll it along the inside perimeter of a larger disk. The following figure depicts the initial situation.

x

y

b b b P

Assume the larger circle has radius R and the smaller circle has radius r. If the center of the smaller circle has argument equal to θ (the angle the segment connecting the center to the origin makes with the positive x-axis), then what is the position of point P ? The following figure depicts the situation:

x

y

b

b

b B

θ b A

R

ϕ

r C

b

P

M 210 — March 22, 2016 page 93

Note that the length of the arc from A to B along the larger circle is equal to Rθ. If angle ϕ is as indicated in the above figure1, then the length of the arc from B to P along the smaller circle is equal to r ϕ. The assumption that the smaller circle rolls inside the larger circle implies that these two arc lengths be equal, so we get the equation r ϕ = Rθ, thus ϕ = (R/r)θ.

We are now in a position to find the coordinates of point P . The following figure shows this point on the smaller circle, enlarged to better see it, and with a horizontal axis added, which divides angle ϕ in two parts: θ and ϕ− θ.

bC

b B

r

b

P

θ

ϕ− θ

The above figure shows the coordinates of point P relative to center C of the small circle to be (r cos(ϕ−

θ),−r sin(ϕ− θ)).

Center C is distance R−r from the origin (center of the large circle), so its coordinates are ((R−r) cos θ, (R−

r) sin θ).

Conclude that point P = (x, y) with

x = (R − r) cos θ + r cos(ϕ− θ) and y = (R− r) sin θ − r sin(ϕ− θ).

Let’s put this to the test in Mathematica using r = R/4. Note that then ϕ = 4θ, so that ϕ− θ = 3θ.

First draw the initial situation:

In[1]:= Graphics[{

Circle[{0, 0}, 1],

Circle[{0.75, 0}, 0.25],

{PointSize[0.012], Red, Point[{1, 0}]}

}]

Next we add the situation for a particular value for θ (once the correct figure shows, we can delete the special value for θ and add code to get the animation).

In[2]:= θ = 35◦;

Graphics[{

Circle[{0, 0}, 1],

Circle[{0.75, 0}, 0.25],

{PointSize[0.012], Red, Point[{1, 0}]},

Circle[{0.75 Cos[θ], 0.75 Sin[θ]}, 0.25],

{PointSize[0.012], Red,

Point[{0.75 Cos[θ] + 0.25 Cos[3 θ], 0.75 Sin[θ] - 0.25 Sin[3 θ]}]} }]

The figure is as before, so we delete the special value of θ, as well as the initial situation, and create an animation as follows.

In[3]:= Animate[

Graphics[{

Circle[{0, 0}, 1],

Circle[{0.75 Cos[θ], 0.75 Sin[θ]}, 0.25],

{PointSize[0.012], Red,

Point[{0.75 Cos[θ] + 0.25 Cos[3 θ], 0.75 Sin[θ] - 0.25 Sin[3 θ]}]} }], {θ, 0, 2π}]

1The drawing of which required the following argument to calculate the exact location of point P in the figure.

M 210 — March 22, 2016 page 94

Finally, we can add the parametric plot traced by point P . First let’s draw this plot by itself, before including it in the animation using Show to combine graphics. We use a different parameter than θ in anticipation of later inserting this code in the animation:

In[4]:= ParametricPlot[

{0.75 Cos[t] + 0.25 Cos[3 t], 0.75 Sin[t] - 0.25 Sin[3 t]}, {t, 0, 2π}, PlotStyle → {Thick, Red}]

Now let’s insert this into the animation, drawing the parametric plot up to θ instead of 2π:

In[5]:= Animate[

Show[

Graphics[{

Circle[{0, 0}, 1],

Circle[{0.75 Cos[θ], 0.75 Sin[θ]}, 0.25],

{PointSize[0.012], Red,

Point[{0.75 Cos[θ] + 0.25 Cos[3 θ], 0.75 Sin[θ] - 0.25 Sin[3 θ]}]} }],

ParametricPlot[

{0.75 Cos[t] + 0.25 Cos[3 t], 0.75 Sin[t] - 0.25 Sin[3 t]}, {t, 0, 2π}, PlotStyle → {Thick, Red}]

], {θ, 0, 2π}]

Example 7. Determine the envelope of the family of lines of TikZercise 3 of Homework 5: the lines connecting points on the unit circle centered at the origin whose polar angles are in the ratio 4 : 1.

Solution. Let’s first draw this family of lines in Mathematica, using the With command that will not make it necessary to clear parameters (given values within this command). The following code will show the unit circle and one of the family of lines:

With[{\[Theta] = 25 \[Degree]},

Graphics[{

Circle[{0, 0}, 1],

Line[{{Cos[\[Theta]], Sin[\[Theta]]}, {Cos[4 \[Theta]], Sin[4 \[Theta]]}}]

}]

]

We draw a family of lines placing a Table command inside Graphics:

Graphics[{

Circle[{0, 0}, 1],

Table[{Thickness[0.001],

Line[{{Cos[\[Theta]], Sin[\[Theta]]}, {Cos[4 \[Theta]],

Sin[4 \[Theta]]}}]}, {\[Theta], 0 \[Degree], 360 \[Degree], 3 \[Degree]}]

}]

The equations of the lines are easily determined: their slopes are

sin(4θ) − sin(θ)

cos(4θ) − cos(θ) ,

so the lines have equations

y = sin(4θ)− sin(θ)

cos(4θ)− cos(θ) (x− cos(θ)) + sin(θ).

We need to optimize these, so for fixed x have Mathematica compute the derivative with respect to θ:

D[(Sin[4 \[Theta]] - Sin[\[Theta]])/(Cos[4 \[Theta]] - Cos[\[Theta]]) (x - Cos[\[Theta]]) +

Sin[\[Theta]], \[Theta]] // Simplify

Find the relation between the critical point (where the above derivative is zero) and x:

Solve[% == 0, x]

M 210 — March 22, 2016 page 95

Next, use replacement to find the corresponding y:

(Sin[4 \[Theta]] - Sin[\[Theta]])/(Cos[4 \[Theta]] - Cos[\[Theta]]) (x - Cos[\[Theta]]) + Sin[\[Theta]]

/. % // Simplify

Put coordinate functions x and y together in ParametricPlot to graph the curve; make use of Show to plot it together with the above graphic displaying the lines.

Homework 8 This assignment consists of only Mathematica problems. Solutions of the problems should be given in a single Mathematica notebook displaying the requested formulas and graphics.

1. Find the exact value of r that creates a perfect 5-pointed star in Example 2.

2. Graph the family of lines connecting the points (a, 0) and (0, b), where a + b = 2, and determine an equation for the envelope of this family of lines2.

3. Graph the family of circles centered at points of the unit circle and all going through the point (1, 0), and determine an equation for the envelope of this family of circles.

4. Determine the envelope of the family of lines of Example 4 of class 6 (March 1): the lines connecting points on the unit circle centered at the origin whose polar angles are in the ratio 3 : 1.

5. Determine the envelope of the family of lines of TikZercise 2 of Homework 5: the lines connecting points on the unit circle centered at the origin whose polar angles are in the ratio 2 : 1.

6. Create an animation of rolling a small disk inside a larger one when the radii are in the ratio 1 : 3.

7. Create an animation of rolling a disk outside a disk of equal radius.

Submit Homework 8 by 3:00pm on Tuesday, March 29, to Moodle.

Please put course, your last name, and homework number in the name of the file you submit (using a file name like M210-HW8-name.nb).

2Note that the lines are parametrized by only one parameter, since the given condition that a+ b = 2 expresses b

in terms of a.

  • Graphics in Mathematica
    • Drawing in Mathematica
    • Envelopes
    • Cycloid Curves

__MACOSX/._M210-S16-class-9.pdf