mathematics notebook 10.3(WOLFRAM MATHEMATICA + LATAX)
untitled folder/.DS_Store
__MACOSX/untitled folder/._.DS_Store
untitled folder/M210 Songyue.pdf
HW 4: I. Solutions of the problems (1, 3, 4, 5, and 6 for optional extra credit) 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). See page 73 of the handouts.
II. Solutions of the problems (1, 4, and 5) 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). See page 83 of the handouts . Solutions of TikZercises 7 and 9 (with 8 as optional extra problem) should be given in a single LaTeX document (see pages 51-52 of the Moodle version of the handouts posted under Class 5); please put your name, the assignment number and date on the top of your homework submission, and also upload a PDF of the typeset document.
III. Solutions of the problems (1, 2, 3, 4, and 5) 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). See page 95 of the handouts.
IV. Solutions of the problems (1, 2, 3, 8, 13, and 14) 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). See pages 112-113 of the handouts (problems 13 and 14 were not on the handout given in class; see page 113 of the Moodle version for these problems).
V. Solutions of the problems 1, 4, 5, and 8 of the handout of April 12 and problems 9 and 10 of the handout of March 29 should be given in a single LaTeX document according to the instructions given on page 130 of the handouts. See pages 112-113 and page 130 of the handouts for the problems.
Due April 24
__MACOSX/untitled folder/._M210 Songyue.pdf
untitled folder/M210-S16-class-10.pdf
M 210 Quadratic Equations in Two Variables March 29, 2016
In this class we will study quadratic equations in two variables: equations of the form
ax2 + bxy + cy2 + dx+ ey + f = 0, (*)
where a, b, c, d, e and f are constants. If a = b = c = 0 the equation is not quadratic, but linear and the equation represents a line, a point, or has empty solution. In order for the equation to be quadratic at least one of a, b, or c must be non-zero. Before we discuss examples of quadratic equations, let’s first recall some useful facts about distance, circles and lines.
Contents
1 Distance 96
2 Circles 97
3 Distance to lines 98
4 Parabolas in standard form 100
5 Ellipses in standard form 103
6 Hyperbolas in standard form 107
7 More examples of quadratic equations 109
1 Distance
The distance between points P1 = (x1, y1) and P2 = (x2, y2) is given by the distance formula
P1P2 = √
(x1 − x2)2 + (y1 − y2)2,
an easy consequence of the Pythagorean Theorem.
This distance is implemented in Mathematica as EuclideanDistance.
Example 1. Find the distance between (2,−1) and (−2, 4), and determine all points (x, y) that have the same distance to (2,−1) as to (−1, 2).
Solution. The distance between (2,−1) and (−2, 4) is computed by the following command.
EuclideanDistance[{1, -2}, {-2, 4}]
The points (x, y) with the same distance to the given pair of points satisfy √
(x− 1)2 + (y + 2)2 = √
(x+ 2)2 + (y − 4)2.
Squaring both sides results in the equation (x− 1)2 + (y+ 2)2 = (x+ 2)2 + (y− 4)2, which is easily solved.
Solve[(x - 1)^2 + (y + 2)^2 == (x + 2)^2 + (y - 4)^2, y]
The following displays the given points, the segment connecting them, and the above set of points, which is the perpendicular bisector of the segment connecting the two given points.
M 210 — March 29, 2016 page 97
Show[{
Graphics[{
{Blue, Thickness[0.005], Line[{{1, -2}, {-2, 4}}]},
{Blue, PointSize[0.015], Point[{{1, -2}, {-2, 4}}]},
Text[Style["(1,-2)", 15], {1, -2} + {0, -.35}],
Text[Style["(-2,4)", 15], {-2, 4} + {0, .35}]
}],
Plot[1/4 (5 + 2 x), {x, -4, 4},
PlotStyle -> {Thickness[0.005], Magenta}]
}]
(1,-2)
(-2,4)
2 Circles
The simplest examples of quadratic equations in two variables x and y are circles. It is an immediate consequence of the distance formula that the circle with center (p, q) and radius r has equation
(x− p)2 + (y − q)2 = r2.
Using Mathematica it is easy to find the circle through any three points (the so-called circumcircle of the triangle).
Example 2. Draw the triangle ABC with A = (0, 0), B = (3, 0) and C = (1, 2), and determines this triangle’s circumcircle.
Solution. The following code will draw the triangle.
Graphics[{
{PointSize[0.01], Point[{{0, 0}, {3, 0}, {1, 2}}]},
Line[{{0, 0}, {3, 0}, {1, 2}, {0, 0}}]
}]
To find a circle through the vertices, assume the center has coordinates (p, q) and the radius is r. Then we have three equations (p−0)2+(q−0)2 = r2, (p−3)2+(q−0)2 = r2, and (p−1)2+(q−2)2 = r2, we can pass on to Mathematica to solve:
Solve[{(p - 0)^2 + (q - 0)^2 == r^2, (p - 3)^2 + (q - 0)^2 == r^2,
(p - 1)^2 + (q - 2)^2 == r^2}, {p, q, r}]
M 210 — March 29, 2016 page 98
3 Distance to lines
The distance between a point (x0, y0) and a line y = mx+ b can be seen from the following figure.1
x axis
y axis
b (x0, y0)
|mx0 + b− y0| d
y = mx+ b
1
m √ 1 +
m 2
By similarity of the two right triangles d
1 =
|mx0 + b− y0|√ 1 +m2
, thus
d = |mx0 + b − y0|√
1 +m2 .
The distance between point (x0, y0) and line ax+ by + c = 0 can be seen from the following figure.
1After R.L. Eisenman, An Easy Way from a Point to a Line, Mathematics Magazine, Vol.42, no.1 (1969), pp.40–41.
M 210 — March 29, 2016 page 99
x axis
y axis
b (x0, y0)
| − c
b − a
b x0 − y0|
d
ax+ by + c = 0, that is, y = − c
b − a
b x
normal vector 〈a, b〉
√ a 2 + b 2|b|
By similarity of the two right triangles d
|b| = | − c
b − a
b x0 − y0|√
a2 + b2 , which implies (multiply by |b|) that
d = |ax0 + by0 + c|√
a2 + b2 .
Example 3. Find the points that are equidistant to the lines y = 2x and x+ y = 3.
Solution. The distance of P = (x, y) to line y = 2x is |y − 2x|/ √ 5, while the distance to the line
x+ y = 3 is |x+ y − 3|/ √ 2. We set these distance equal to each other and solve:
|y − 2x|√ 5
= |x+ y − 3|√
2 .
Stripping absolute values, we have the two equations
y − 2x√ 5
= x+ y − 3√
2 and
y − 2x√ 5
= −x+ y − 3√ 2
.
We can use Mathematica to solve each of these equations:
Solve[(y - 2 x)/Sqrt[5] == (x + y - 3)/Sqrt[2], y]
and
Solve[(y - 2 x)/Sqrt[5] == -(x + y - 3)/Sqrt[2], y]
We can convert the answers to TEX code that can be copied in a LATEX document. For example, following the output of
Solve[(y - 2 x)/Sqrt[5] == (x + y - 3)/Sqrt[2], y]
we can enter
y /. % // TeXForm
to see that2
y = −4
√ 5x− 5
√ 2x+ 15
√ 2
5 √ 2− 2
√ 5
.
2Copy the TEX code except the outside braces, then place small spaces between the coefficients and the x’s.
M 210 — March 29, 2016 page 100
Similarly, the other solution is
y = 4 √ 5x− 5
√ 2 x+ 15
√ 2
5 √ 2 + 2
√ 5
.
The following code displays the two given lines and the above two solutions (in magenta and cyan, respectively).
Show[{
Plot[2 x, {x, -1, 4}, AspectRatio -> Automatic, PlotRange -> {{-1.1, 4.1}, {-1.1, 4.1}}],
Plot[3 - x, {x, -1, 4}],
Plot[(15 Sqrt[2] - 5 Sqrt[2] x - 4 Sqrt[5] x)/(5 Sqrt[2] - 2 Sqrt[5]),
{x, -1, 4}, PlotStyle -> Magenta],
Plot[(3 Sqrt[5] + 2 Sqrt[2] x - Sqrt[5] x)/(Sqrt[2] + Sqrt[5]),
{x, -1, 4}, PlotStyle -> Cyan]
}]
-1 1 2 3 4
-1
1
2
3
4
The magenta line is the angle bisector of angle at C in △ABC of the previous example. The other angle bisectors can be computed similarly. The triangle’s incircle is centered at their point of intersection.
4 Parabolas in standard form
Let c be a positive real number. Find all points P in the plane that have equal distance to the line y = −c as to the point F = (0, c).
M 210 — March 29, 2016 page 101
x
y
F = (0, c)
P = (x, y)
−c
c
An equation is readily found: if P = (x, y), the condition is
d(P, F ) = y + c.
This is equivalent to x2 + (y − c)2 = (y + c)2
which is equivalent with x2 = (y + c)2 − (y − c)2 = 4cy,
or
y = 1
4c x2.
The parabola with focus F = (0, c) and directrix y = −c has equation y = 1
4c x2. This is called the
standard equation for the parabola. Note that the vertex of this parabola is the point (0, 0).
Example 4. Determine the directrix and focus of the parabola y = 9− x− x2/6.
Solution. First we find the vertex of this parabola. We can use algebra or calculus.
The Mathematica code
D[9 - x - x^2/6, x]
Solve[% == 0, x]
9 - x - x^2/6 /. %
gives the vertex. We can check the answer:
21/2 - 1/6 (x + 3)^2 // Expand
The parabola is to be shifted over (−3, 21/2) to get it into standard form. We find the value c that determines the focus and directrix by setting the coefficient of x2 equal to 1/(4c):
Solve[1/(4 c) == -(1/6), c]
The parabola’s focus is the point (−3, 21/2 − 3/2) = (−3, 9). The parabola’s directrix is the line y = 9.
The following animation displays the meaning of focus and directrix for this parabola.
M 210 — March 29, 2016 page 102
Manipulate[
Show[{
Plot[21/2 - 1/6 (x + 3)^2, {x, -11, 5}, AspectRatio -> Automatic,
PlotStyle -> Blue, PlotRange -> {{-11, 5}, {0, 12.25}}],
Graphics[{
{Blue, PointSize[0.015], Point[{t, 21/2 - 1/6 (t + 3)^2}]},
Line[{{t, 12}, {t, 21/2 - 1/6 (t + 3)^2}, {-3, 9}}],
{Gray, Circle[{t, 21/2 - 1/6 (t + 3)^2}, 3/2 + 1/6 (t + 3)^2]},
{Red, PointSize[0.015], Point[{-3, 9}]},
{Red, Line[{{-11, 12}, {5, 12}}]}
}]
}], {{t, -3}, -11, 5}]
Example 5. Determine an equation for the parabola with directrix x+ 2y = 4 and focus (3, 2).
Solution. We first plot the directrix and point:
Show[{
Plot[(4 - x)/2, {x, -1, 5}, PlotRange -> {{-1, 5}, {-1, 5}},
AspectRatio -> Automatic, PlotStyle -> Red],
Graphics[{
{Red, PointSize[0.012], Point[{3, 2}]}
}]
}]
-1 1 2 3 4 5
-1
1
2
3
4
5
The distance of point (x, y) to line x+ 2y = 4 is |x+ 2y − 4|√
5 , so the parabola is determined by the
equation √
(x− 3)2 + (y − 2)2 = |x+ 2y − 4|√
5 .
Use Mathematica to square both sides of this equation and simplify the answer:
(x - 3)^2 + (y - 2)^2 - ((x + 2 y - 4)/Sqrt[5])^2 // Expand
%*5 // Expand
M 210 — March 29, 2016 page 103
The parabola’s equation is 4x2 − 4xy − 22x+ y2 − 4y + 49 = 0, and it is plotted together with the directrix and focus by the following code.
Show[{
Plot[(4 - x)/2, {x, -1, 6}, PlotRange -> {{-1.1, 6.1}, {-1.1, 6.1}},
AspectRatio -> Automatic, PlotStyle -> Red],
Graphics[{
{Red, PointSize[0.012], Point[{3, 2}]}
}],
ContourPlot[
4 x^2 - 4 x y - 22 x + y^2 - 4 y + 49 == 0, {x, -1.1, 6.1}, {y, -1.1, 6.1},
ContourStyle -> Blue]
}]
-1 1 2 3 4 5 6
-1
1
2
3
4
5
6
5 Ellipses in standard form
Geometric Description. Given two points F1 and F2 in the plane, and a positive number a larger than half of F1F2, the set of points P such that PF1 + PF2 = 2a is an ellipse with foci F1 and F2. The standard form is obtained if F1 and F2 lie on one of the coordinate axes with their midpoint at the origin.
Case 1: The points F1 and F2 lie on the x-axis with their midpoint at the origin. Then we may assume that F1 = (c, 0) and F2 = (−c, 0) with c > 0. The following figure displays one point P on the ellipse.
M 210 — March 29, 2016 page 104
x
y
F1F2
a b
c
The figure shows that a2 = b2 + c2.
The rectangular equation in standard form is easily derived: simplify the equation
√
(x− c)2 + y2 + √
(x+ c)2 + y2 = 2a,
by isolating the square roots and repeatedly squaring both sides of the equation: the computations
Sqrt[(x - c)^2 + y^2]^2 - (2 a - Sqrt[(x + c)^2 + y^2])^2 // Expand
(4 a Sqrt[(c + x)^2 + y^2])^2 - (4 a^2 + 4 c x)^2 // Expand
show that the equation is equivalent with
(a2 − c2)x2 + a2y2 = a2(a2 − c2),
that is, b2x2 + a2y2 = a2b2,
or (divide by a2b2): x2
a2 +
y2
b2 = 1.
Note that a is half the horizontal axis of the ellipse. The following figure shows quantities a and b:
M 210 — March 29, 2016 page 105
x
y
F1F2
aa b
cc
a
b
Case 2: The points F1 and F2 lie on the y-axis with their midpoint at the origin. Then we may assume that F1 = (0, c) and F2 = (0,−c) with c > 0. The following figure displays one point P on the ellipse.
x
y
F1
F2
a
b
c
Example 6. Find the foci of the ellipse with equation
4x2 + 6y2 = 24.
Solution. Divide by 24 to get the equation in standard form:
x2
6 +
y2
4 = 1.
The ellipse’s axes have half-lengths a = √ 6 and b = 2. c2 = a2 − b2 = 2, so c =
√ 2. The foci are at
( √ 2, 0) and (−
√ 2, 0).
M 210 — March 29, 2016 page 106
Example 7. Find a quadratic equation for the ellipse with foci at (3,−1) and (−1, 3), going through the point (4,−2).
Solution. The distance c is here equal to
c=EuclideanDistance[{-1, 3}, {3, -1}]/2
The ellipse is centered at the midpoint of segment F1F2:
({-1, 3}+{3, -1})/2
Half the major axis is here
a=EuclideanDistance[{1, 1}, {4, -2}]
The equation is thus
√
(x− 3)2 + (y + 1)2 + √
(x+ 1)2 + (y − 3)2 = 6 √ 2.
We convert this equation into one of the form (*) using Mathematica:
Sqrt[(x - 3)^2 + (y + 1)^2]^2 - (6 Sqrt[2] - Sqrt[(x + 1)^2 + (y - 3)^2])^2 // Expand
Conclude that the ellipse has quadratic equation 7x2 + 4xy + 7y2 − 18x− 18y = 72. The following code
Show[{
Graphics[{
{Red, PointSize[0.015], Point[{{-1, 3}, {3, -1}}]},
{Blue, PointSize[0.015], Point[{{4, -2}}]}
}],
ContourPlot[
7 x^2 + 4 x y + 7 y^2 - 18 x - 18 y == 72, {x, -5, 5}, {y, -5, 5},
ContourStyle -> {Blue, Thick}]
}]
draws the graph:
M 210 — March 29, 2016 page 107
6 Hyperbolas in standard form
Geometric Description. Given two points F1 and F2 in the plane, and a positive number a, the set of points P such that |PF1 − PF2| = 2a is an hyperbola with foci F1 and F2. The standard form is obtained if F1 and F2 lie on one of the coordinate axes with their midpoint at the origin.
Case 1: Foci F1 = (c, 0) and F2 = (−c, 0). Equation
√
(x+ c)2 + y2 − √
(x− c)2 + y2 = 2a.
Writing the equation as √
(x+ c)2 + y2 = 2a+ √
(x− c)2 + y2,
squaring both sides yields the equation
(x+ c)2 + y2 = 4a2 + 4a √
(x− c)2 + y2 + (x − c)2 + y2,
so 4a
√
(x− c)2 + y2 = (x+ c)2 + y2 − ((x − c)2 + y2)− 4a2 = 4cx− 4a2,
thus a √
(x− c)2 + y2 = cx− a2.
Squaring once more results in the equation
a2((x− c)2 + y2) = c2x2 − 2a2cx+ a4,
which is equivalent to
a2x2 − 2a2cx+ a2c2 + a2y2 = a4 − 2a2cx+ c2x2,
and simplifies to (c2 − a2)x2 − a2y2 = a2(c2 − a2).
We have c > a, so c2 − a2 > 0, and we can put b = √ c2 − a2. Using that c2 − a2 = b2 this equation
becomes b2x2 − a2y2 = a2b2.
Finally, dividing by a2b2 results in the equation
x2
a2 − y2
b2 = 1.
This is the standard equation for the hyperbola. The foci of this hyperbola are at (±c, 0), where c2 = a2 + b2.
Case 2: In case the foci are at the points (0,±c), the hyperbola has equation
x2
a2 − y2
b2 = −1.
In either of these standard forms, the curve has asymptotes given by the equations
x2
a2 − y2
b2 = 0.
Example 8. Determine the foci of the hyperbola with equation x2 − y2 = 1.
Solution. The equation is in standard form with a = b = 1. We have c2 = a2 + b2 = 2, so the foci are at the points (
√ 2, 0) and (−
√ 2, 0). The following figure illustrates that the points on the right
branch of this hyperbola all have distance √ 2 more to F2 than to F1.
M 210 — March 29, 2016 page 108
F1F2
The asymptotes are here the lines satisfying x2 − y2 = 0, that is, the lines y = x and y = −x, illustrated in the following graph of the whole hyperbola.
F1F2
Example 9. Find an equation for the hyperbola with foci at (4,−2) and (−2, 4), with vertices at the points (3,−1) and (−1, 3).
Solution. The distance c is here equal to
c=EuclideanDistance[{-2, 4}, {4, -2}]/2
The hyperbola is centered at the midpoint of segment F1F2:
M 210 — March 29, 2016 page 109
({-2, 4}+{4, -2})/2
Half the distance between the vertices is
a=EuclideanDistance[{-3, 1}, {3, -1}]/2
The equation is thus
√
(x− 4)2 + (y + 2)2 − √
(x+ 2)2 + (y − 4)2 = ±2a.
Use Mathematica to convert this in the form (*).
7 More examples of quadratic equations
Example 10. Find the quadratic equation of the parabola with focus (3, 2) and directrix x+2y = 4.
Solution. First draw the directrix and focus: this can be done using the code
Show[{
Plot[(4 - x)/2, {x, -1, 6}, PlotRange -> {{-1.1, 6.1}, {-1.1, 6.1}},
AspectRatio -> Automatic, PlotStyle -> Red],
Graphics[{
{Red, PointSize[0.012], Point[{3, 2}]}
}]
}]
The distance of P = (x, y) to line x+ 2y = 4 is
|x+ 2y − 4|√ 5
.
The distance between P = (x, y) and F = (3, 2) is
PF = √
(x− 3)2 + (y − 2)2.
So the parabola has equation
|x+ 2y − 4|√ 5
= √
(x− 3)2 + (y − 2)2.
Square both sides to rewrite the equation in the form
(
x+ 2y − 4√ 5
)2
= (x− 3)2 + (y − 2)2.
We find the equation in above form by entering the following into Mathematica:
(x - 3)^2 + (y - 2)^2 - ((x + 2 y - 4)/Sqrt[5])^2 // Expand
We can get rid of fractions by entering:
% * 5 // Expand
The answer is the quadratic 4x2 − 4xy − 22x+ y2 − 4y + 49 = 0. We can plot this into the above figure showing directrix and focus adding the following command inside the Show we already used to draw the above figure:
M 210 — March 29, 2016 page 110
ContourPlot[4 x^2-4 x y-22 x+y^2-4 y+49==0,{x,-1,5},{y,-1,5}, ContourStyle->Blue]
Example 11. Draw the points (0, 2), (0,−1), (1, 1), (1,−2), (−2, 0), determine a quadratic equation that goes through each of these points, and draw it together with the points.
Solution. The following code will draw these points.
pts = {{0, 2}, {0, -1}, {1, 1}, {1, -2}, {-2, 0}};
Graphics[{
{Blue, PointSize[0.015], Point[pts]}
}]
We set up a system of equations as follows. In equation ax2+ bxy+ cy2+dx+ ey+ f = 0 substitute for x and y the values for each of the given points to obtain a system of as many equations. For the first point in our list pts the code
a x^2 + b x y + c y^2 + d x + e y + f /. {x -> pts[[1]][[1]], y -> pts[[1]][[2]]}
will do the substitution. We do this for all points in list pts, then solve the system of equations:
lhs = Table[ a x^2 + b x y + c y^2 + d x + e y + f
/. {x -> pts[[j]][[1]], y -> pts[[j]][[2]]}, {j, 1, 5}]
Solve[Table[lhs[[j]] == 0, {j, 1, 5}], {a, b, c, d, e, f}]
Since Mathematica’s answer is a list of replacement rules, we obtain the quadratic by
a x^2 + b x y + c y^2 + d x + e y + f /. %
Factor[%]
We can make use of ContourPlot to graph the equation. Here’s the code that draws the answer for this example.
Show[{
Graphics[{
{Blue, PointSize[0.015], Point[pts]}
}],
ContourPlot[6 + 13 x + 5 x^2 - 6 y^2 == 0, {x, -5, 3}, {y, -4, 4},
ContourStyle -> Blue]
}, Frame -> True]
Example 12. Draw the triangle with vertices at (1, 0), (1/3, 1), (−1, 0). Find an ellipse that touches the triangle at the midpoints of each of its sides.
Solution. The following code will draw the triangle and the midpoints of its sides.
Graphics[{
Point[{{-1, 0}, {1, 0}, {1/3, 1}}],
Line[{{-1, 0}, {1, 0}, {1/3, 1}, {-1, 0}}],
Point[{{0, 0}, {2/3, 1/2}, {-1/3, 1/2}]
}]
M 210 — March 29, 2016 page 111
The condition of touching at the midpoints needs to be translated in equations. Clearly the three midpoints must lie on the quadratic ax2 + bxy+ cy2 + dx+ ey+ f = 0, resulting in three equations. The following code will generate the coefficients for these three equations:
a x^2 + b x y + c y^2 + d x + e y + f /.
{{x -> 0, y -> 0}, {x -> 2/3, y -> 1/2}, {x -> -1/3, y -> 1/2}}
But we are also given the derivatives dy/dx at each of the midpoints: they need to be equal to the slopes of the sides of the triangle. We can find dy/dx by implicit differentiation of the equation ax2 + bxy + cy2 + dx+ ey + f = 0:
2ax+ by + bx dy
dx + 2cy
dy
dx + d+ e
dy
dx = 0.
Collecting terms containing dy/dx:
(bx+ 2cy + e) dy
dx = −(2ax+ by + d),
so dy
dx = −2ax+ by + d
bx+ 2cy + e .
The slopes of the tangent lines at each of the midpoints can be obtained by
-((2 a x + b y + d)/(b x + 2 c y + e)) /.
{{x -> 0, y -> 0}, {x -> 2/3, y -> 1/2}, {x -> -1/3, y -> 1/2}}
The slopes are easily seen to be 0, -3/2 and 3/4. We need to solve the following system of equations:
Solve[{f == 0, (4 a)/9 + b/3 + c/4 + (2 d)/3 + e/2 + f == 0,
a/9 - b/6 + c/4 - d/3 + e/2 + f == 0, d == 0,
-(((4 a)/3 + b/2 + d)/((2 b)/3 + c + e)) == -3/2,
-((-((2 a)/3) + b/2 + d)/(-(b/3) + c + e)) == 3/4}, {a, b, c, d, e, f}]
We get the quadratic from
a x^2 + b x y + c y^2 + d x + e y + f /. % // Expand // Factor
The ellipse has equation 9x2 − 18y− 6xy + 28y2 = 0. The following code graphs it inside the figure for the triangle.
Show[{
Graphics[{
Point[{{-1, 0}, {1, 0}, {1/3, 1}}],
Line[{{-1, 0}, {1, 0}, {1/3, 1}, {-1, 0}}],
Point[{{0, 0}, {2/3, 1/2}, {-1/3, 1/2}]
}],
ContourPlot[9 x^2 - 18 y - 6 x y + 28 y^2 == 0, {x, -1, 1}, {y, 0, 2/3}]
}]
M 210 — March 29, 2016 page 112
Homework 9 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. Show that the polygon through the four points (21, 0), (8, 5), (0, 8), (13, 3) is a parallelogram, and compute its area (see the document “Comments on Homework Assignments 3–5” posted on Moodle).
2. Find the perpendicular bisectors of each of the sides of the triangle of Example 1, and use them to find the circumcircle of the triangle.
3. Find the exact incircle of the triangle of Example 2. This is the circle inside the triangle that touches each of the triangle’s sides drawn in the following figure.
4. Determine the curves that appear in the Moiré pattern of Exercise 6 of class 6 (March 1) on page 61, and draw these curves together with the pattern.
5. Draw concentric families of circles with integer radii centered at the two points (2, 0) and (−2, 0).
M 210 — March 29, 2016 page 113
Determine the curves that appear in the above Moiré pattern, and draw these curves together with the pattern.
6. Show that the tangent line at the point (x0, y0) on the ellipse
x2
a2 +
y2
b2 = 1
has equation x0x
a2 +
y0y
b2 = 1.
7. Show that the tangent line at the point (x0, y0) on the hyperbola
x2
a2 − y2
b2 = 1
has equation x0x
a2 − y0y
b2 = 1.
8. Find the quadratic equation of the parabola with focus (3, 2) and directrix 2x− y = 4.
9. Draw the points (3, 0), (0, 3), (−3, 0), (0,−3), (1, 1). Find a quadratic through the above points, and graph it with the above points.
10. Draw the points (1, 0), (−1, 0), (0, 1), (0,−1), (2, 2). Find a quadratic through the above points, and graph it with the above points.
11. Draw the points (0, 1), (0,−1), (1, 2), (1,−2), (−2, 0). Find a quadratic through the above points, and graph it with the above points.
12. Find the quadratic equation for the ellipse touching the midpoints of the sides of the triangle of Example 2, and graph it with this triangle.
13. Determine the directrix and focus of the parabola y = 1
12 x2 − x− 2.
14. Find the quadratic equation for the ellipse with foci (2, 1) and (−2,−1) going through the points (−1, 2) and (1,−2).
Submit Homework 9 by 3:00pm on Tuesday, April 12, 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-HW9-name.nb).
- Distance
- Circles
- Distance to lines
- Parabolas in standard form
- Ellipses in standard form
- Hyperbolas in standard form
- More examples of quadratic equations
__MACOSX/untitled folder/._M210-S16-class-10.pdf
untitled folder/M210-S16-class-6.pdf
M 210 More Drawing in LATEX March 1, 2016
Repeating Commands
Drawing instructions in TikZ can be repeated by making use of \foreach, specifying the variable (starting with a backslash) and iterator set, and then enclosing the drawing commands to be repeated in braces.
Example 1. Let’s illustrate the use of \foreach by drawing the following polar grid.
x
y
To get started enter the following in a LATEX document using the tikz package.
LATEX\begin{center}
\begin{tikzpicture}[>=stealth]
\draw[->] (-3.25,0) -- (3.5,0) node [above] {$x$};
\draw[->] (0,-3.25) -- (0,3.5) node [right] {$y$};
\foreach \r in {1,2,3} {\draw (0,0) circle (\r); }
\end{tikzpicture}
\end{center}
Notice that the arrowstyle is globally redefined to stealth by using >=stealth as optional argument of the tikzpicture environment (equivalently use \tikzset{>=stealth} before the tikzpicture
environment). The set of values for the radius \r in \foreach is given in set notation.
Add the rays to obtain the above figure. One way is to add the following line of code in the tikzpicture environment.
LATEX\foreach \a in {30,60,120,150,210,240,300,330} { \draw (0,0) -- (\a:3.25); }
It is not necessary to list all possible angles \a in the drawing command \draw (0,0) -- (\a:3.25) ;, it is enough to place the initial value, next value, and final value in the braces denoting the set over which \a varies. For example, we can add
LATEX\foreach \a in {30,120,...,300} { \draw (0,0) -- (\a:3.25); }
to obtain the rays with angles 30◦ to 300◦ in increments of 120◦−30◦ = 90◦. The four remaining rays can then be drawn similarly. An alternative is to draw also rays corresponding the the coordinate axes (these will then be drawn over or below these axes, depending where in the tikzpicture the drawing command is given), so that we can simply use the following line of additional code.
LATEX\foreach \a in {0,30,...,330} { \draw (0,0) -- (\a:3.25); }
M 210 — March 1, 2016 page 54
Example 2. The following code draws many circles of the same radius at various points in a circle.
LATEX\begin{center}
\begin{tikzpicture}
\foreach \a in {0,10,...,360} { \draw[line width=.5pt] (\a:2) circle(1.5); }
\end{tikzpicture}
\end{center}
See what happens if you replace 10 in the above code by 5.
Example 3. Let’s draw a grid of evenly divided lines parallel to the sides of the parallelogram with vertices at (0, 0), (5, 0), (7, 3) and (2, 3), shown in the following figure.
First draw horizontal lines, connecting points (1, 0), (2, 0), (3, 0), and (4, 0) to corresponding points on the parallelogram’s top edge, which is 2 units shifted to the right, so the points on the top corresponding to the above points are (1 + 2, 3), (2 + 2, 3), (3 + 2, 3), and (4 + 2, 3). We connect points (h, 0) and (h+ 2, 3), for each h in set {1, 2, 3, 4}. This can be accomplished by the following addition to the code for the parallelogram.
LATEX\foreach \h in {1,2,3,4} {\draw[blue!50] (\h,0) -- ({\h+2},3); }
Next we draw the horizontal lines. The line through (0, 0) and (2, 3) has equation y = 3x/2. If we want to add three horizontal equally spaced lines, they need to be 3/4 vertical units apart. If y = 3/4, then x = 1/2. The points on the left side of the parallelogram will be (k/2, 3k/4), where k is in set {0, 1, 2, 3, 4}. We do not need to draw the first and last (corresponding to bottom and top of the parallelogram), so these lines can be drawn by adding the following code.
LATEX\foreach \k in {1,2,3} {\draw[blue!50] ({\k/2},{\k*3/4}) -- ({\k/2+5},{\k*3/4}); }
Example 4. Draw a circle centered at the origin, and connect points on this circle whose polar angles are in the ratio 3 : 1.
Solution. We first draw the unit circle, and scale the figure by a factor 4:
LATEX\begin{center}
\begin{tikzpicture}[scale=4]
\draw (0,0) circle (1);
\end{tikzpicture}
\end{center}
Next let’s draw one of the lines: draw the line connecting the points with polar coordinates corre- sponding to angles 40 and 3× 40 degrees, by adding the following line of code.
LATEX\draw (40:1)--({3*40}:1);
Finally replace 40 by an angle \a and use a foreach command to draw multiple lines. Set the line width to very thin or thinner to get a nice figure.
M 210 — March 1, 2016 page 55
Example 5. A line segment of length 1 has its end points on two of the three equiangular rays emanating from the origin, as shown in the following figure.
1
θ
Determine the coordinates of the end points of the segment, and use these to draw the envelope of all segments of length 1 whose end points are on two of the three rays.
Solution. The following figure will be useful in finding the coordinates.
cos θ
si n θ
A
B
1
θ120 ◦
We isolate the following 30-60-90 triangle:
60 ◦
si n θ
h
If h is as indicated in this 30-60-90 triangle, then tan 60◦ = sin θ/h implies that
h = sin θ
tan 60◦ =
sin θ√ 3 .
It follows that points A and B indicated in the above figure are
A =
(
cos θ − sin θ√ 3 , 0
)
and B =
(
− sin θ√ 3 , sin θ
)
.
M 210 — March 1, 2016 page 56
With these coordinates we can draw the line segment. The following code will do this for angle θ = 35◦:
LATEX\begin{center}
\begin{tikzpicture}[scale=3.75]
\draw (0,0)--(0:1.2);
\draw (0,0)--(120:1.2);
\draw (0,0)--(240:1.2);
\draw ({cos(35)-sin(35)/sqrt(3)},0)--({-sin(35)/sqrt(3)},{sin(35)});
\end{tikzpicture}
\end{center}
Now, place a \foreach in the last line, using iterator \a in set {35}:
LATEX\begin{center}
\begin{tikzpicture}[scale=3.75]
\draw (0,0)--(0:1.2);
\draw (0,0)--(120:1.2);
\draw (0,0)--(240:1.2);
\foreach \a in {35} ({cos(\a)-sin(\a)/sqrt(3)},0)--({-sin(\a)/sqrt(3)},{sin(\a)});}
\end{tikzpicture}
\end{center}
Next change the iterator set to start at angle 0◦, end at angle 60◦, with increments equal to 2◦. Also reduce the line width to get a better image. The code
LATEX\begin{center}
\begin{tikzpicture}[scale=3.75]
\draw (0,0)--(0:1.2);
\draw (0,0)--(120:1.2);
\draw (0,0)--(240:1.2);
\foreach \a in {0,2,...,60}
{\draw[very thin] ({cos(\a)-sin(\a)/sqrt(3)},0)--({-sin(\a)/sqrt(3)},{sin(\a)});}
\end{tikzpicture}
\end{center}
results in the figure:
To draw the segments in the two other regions, we could repeat the above argument to express the coordinates of an arbitrary line segment in terms of an angle, but here it is easier to simply rotate
M 210 — March 1, 2016 page 57
the segments over angles 120◦ and 240◦. The rotations (around the origin) are specified by the optional arguments rotate=120 and rotate=240 (or equivalently rotate=-120) of \draw.
The following code illustrates this for a single line segment.
LATEX\begin{center}
\begin{tikzpicture}[scale=3.75]
\draw (0,0)--(0:1.2);
\draw (0,0)--(120:1.2);
\draw (0,0)--(240:1.2);
\draw[thick] ({cos(35)-sin(35)/sqrt(3)},0)--({-sin(35)/sqrt(3)},{sin(35)});
\draw[thick,rotate=120] ({cos(35)-sin(35)/sqrt(3)},0)--({-sin(35)/sqrt(3)},{sin(35)});
\draw[thick,rotate=240] ({cos(35)-sin(35)/sqrt(3)},0)--({-sin(35)/sqrt(3)},{sin(35)});
\end{tikzpicture}
\end{center}
The above code produces the following figure.
Finally, to get the desired envelope of the segments, use the above rotations in the figure with the repeated segments.
The code
LATEX\begin{center}
\begin{tikzpicture}[scale=3.75]
\draw (0,0)--(0:1.2);
\draw (0,0)--(120:1.2);
\draw (0,0)--(240:1.2);
\foreach \a in {0,2,...,60} {\draw[very thin]
({cos(\a)-sin(\a)/sqrt(3)},0)--({-sin(\a)/sqrt(3)},{sin(\a)});}
\foreach \a in {0,2,...,60} {\draw[very thin,rotate=120]
({cos(\a)-sin(\a)/sqrt(3)},0)--({-sin(\a)/sqrt(3)},{sin(\a)});}
\foreach \a in {0,2,...,60} {\draw[very thin,rotate=240]
({cos(\a)-sin(\a)/sqrt(3)},0)--({-sin(\a)/sqrt(3)},{sin(\a)});}
\end{tikzpicture}
\end{center}
M 210 — March 1, 2016 page 58
results in the following figure.
M 210 — March 1, 2016 page 59
Homework 5
TikZercises. Draw the following in a LATEX document using TikZ:
1. Draw the following polar grid.
x
y
2. Draw a circle centered at the origin, and connect points on this circle whose polar angles are in the ratio 2 : 1.
3. Draw a circle centered at the origin, and connect points on this circle whose polar angles are in the ratio 4 : 1.
4. A line segment of length 1 has its end points on the coordinate axes, as shown in the following figure.
M 210 — March 1, 2016 page 60
1
θ
Determine the coordinates of the end points of the segment, and use these to draw the envelope of all segments of length 1 whose end points are on the x- and y-axis.
5. The following figure displays the unit circle, a point P on this circle corresponding to angle θ, and a circle centered at P tangential to the y-axis.
y
x
P
θ
M 210 — March 1, 2016 page 61
Draw the unit circle, part of the y-axis extending above and below the unit circle, and a number of circles tangential to the y-axis large enough so that an enveloping curve shows (take angles θ equidistant).
6. Draw the following figure displaying a patterns of concentric circles and parallel lines.
Submit Homework 5 by 3:00pm on Tuesday, March 8, 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-HW5-name).
__MACOSX/untitled folder/._M210-S16-class-6.pdf
untitled folder/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/untitled folder/._M210-S16-class-7.pdf
untitled folder/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/untitled folder/._M210-S16-class-8.pdf
untitled folder/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