More Useful Trig Graphics

First off, wow, that unit circle post was by far the most viewed I’ve had.  So maybe people would also be interested in this too.

The thing that’s difficult about graphing trig functions for the first time is that regular old graph paper just isn’t up to the job.  When we have points like \left(\frac{\pi}{4} , \frac{\sqrt2}{2} \right) and \left(\frac{\pi}{3} , \frac{\sqrt3}{2} \right) to plot, you need something that is suited to the task, and the numbers involved.  I have met teachers that say they just have students plot the multiples of \frac{\pi}{2} , and then tell the students to trust them, it’s not really a zig-zag.  And it seems to me that having them spend time plotting points in order to develop a wrong intuition is an amazingly bad use of time.  You could just use the calculator and it would be better. But in order to make the time spent plotting points valuable you have to be able to see the shape of the curve from the points are plotted. So you need y-values of \pm\frac{\sqrt2}{2} and \pm\frac{\sqrt3}{2} and x-values that are multiples of \frac{\pi}{6} and \frac{\pi}{4}.

So behold:

triggraph

Of course, you need a key for this:

triggraph-key

You also need to call the students’ attention to how the x-gridlines aren’t evenly spaced, and that the unlabeled ones are multiples of \frac{\pi}{6} and \frac{\pi}{4}.  But after that…

triggraph-dots

you have something that can allow student to connect their knowledge of the trig functions in the context of the unit circle to the traditional graphing context.

I don’t feel like wrestling with the code tags, so you can check out the latex source here, at sharelatex.  (You don’t need a ShareLaTeX account to access that link, but if you’d like to sign up for one, please use this referral link, which lets me earn points toward referral bonuses. Thanks!)  That document has two types of graphs– one for sine and cosine, and another for tangent and cotangent.  There’s a second set with the functions graphed as well, which I don’t give to students, but it’s useful to have to point at in later classes.

TikZ Unit Circle

After getting several requests from IRL folks for my unit circle, I figured I’d make it a post here. (Seriously, when I get tackled in the hall for a unit circle handout, it means that there’s a real need out there, even though I would have figured that there’s enough unit circles in the world.)

Blank unit circle
blank unit circle

blank unit circle as pdf

latex code on sharelatex.
latex code:

\documentclass[border=4pt]{standalone}
\usepackage{amsmath,mathpazo,gensymb}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture} [>=stealth, scale=2.5,
% Toggle commenting on the next four lines for the completed unit circle:
angle/.style={draw,text=white,fill=white,minimum height=1cm, minimum width=1cm},
point/.style={white},
%angle/.style={fill=white},
%point/.style={},
]
	\draw [white] (-3.6,-3.6) rectangle (3.6,3.6);
	\draw [thick,fill=white] (0,0) circle (3cm);
	\draw [thick, ] (-3.3,0) -- (3.3,0);
	\draw [thick, ] (0,-3.3) -- (0,3.3);
	\draw (0,0) --  node [angle] {$\frac{\pi}{2}$} (90:3)
				node[point, above right] {$ \left(0,1\right) $};
	\draw (0,0) --  node [angle] {\footnotesize{$\pi$}} (180:3)
				node[point, above left] {$ \left(-1,0\right) $};
	\draw (0,0) --  node [angle] {$\frac{3\pi}{2}$} (270:3)
				node[point, below right] {$ \left(0,-1\right) $};
	\draw (0,0) --  node [angle] {\footnotesize{$2\pi$}} (0:3)
				node[point, above right] {$ \left(1,0\right) $};
	\draw (0,0) --  node [angle] {$\frac{\pi}{4}$} (45:3)
				node [point, above right] {$ \left( \frac{\sqrt2}{2} , \frac{\sqrt2}{2}  \right) $};
	\draw (0,0) --  node [angle] {$\frac{3\pi}{4}$} (135:3)
				node [point, above left] {$ \left( -\frac{\sqrt2}{2} , \frac{\sqrt2}{2}  \right) $};
	\draw (0,0) --  node [angle] {$\frac{5\pi}{4}$} (225:3)
				node [point, below left] {$ \left( -\frac{\sqrt2}{2} , -\frac{\sqrt2}{2}  \right) $};
	\draw (0,0) --  node [angle] {$\frac{7\pi}{4}$} (315:3)
				node [point, below right] {$ \left( \frac{\sqrt2}{2} , -\frac{\sqrt2}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{\pi}{6}$} (30:3)
				node [point, above right] {$ \left( \frac{\sqrt3}{2} , \frac{1}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{\pi}{3}$} (60:3)
				node [point, above right] {$ \left( \frac{1}{2} , \frac{\sqrt3}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{2\pi}{3}$} (120:3)
				node [point, above left] {$ \left( -\frac{1}{2} , \frac{\sqrt3}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{5\pi}{6}$} (150:3)
				node [point, above left] {$ \left(- \frac{\sqrt3}{2} , \frac{1}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{7\pi}{6}$} (210:3)
				node [point, below left] {$ \left(- \frac{\sqrt3}{2} , -\frac{1}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{4\pi}{3}$} (240:3)
				node [point, below left] {$ \left( -\frac{1}{2} , -\frac{\sqrt3}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{5\pi}{3}$} (300:3)
				node [point, below right] {$ \left( \frac{1}{2} , -\frac{\sqrt3}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{11\pi}{6}$} (330:3)
				node [point, below right] {$ \left( \frac{\sqrt3}{2} , -\frac{1}{2}  \right) $};

	\foreach \n in {1,2,3,4}
		\foreach \t in {0,30,45,60}
			\fill (\n*90+\t:3) circle (0.03cm);
	\foreach \t in {30,45,60, 120,135,150, 210,225,240, 300,315,330}
		\node [font=\tiny, fill=white,inner sep=1pt] at (\t:.75) {$ \t\degree $};
\end{tikzpicture}

\end{document}

Completed Unit Circle
completed unit circle

completed unit circle as pdf

latex code on sharelatex
Get the latex code here.

\documentclass[border=4pt]{standalone}
\usepackage{amsmath,mathpazo,gensymb}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture} [>=stealth, scale=2.5,
% Toggle commenting on the next four lines for the completed unit circle:
%angle/.style={draw,text=white,fill=white,minimum height=1cm, minimum width=1cm},
%point/.style={white},
angle/.style={fill=white},
point/.style={},
]
	\draw [white] (-3.6,-3.6) rectangle (3.6,3.6);
	\draw [thick,fill=white] (0,0) circle (3cm);
	\draw [thick, ] (-3.3,0) -- (3.3,0);
	\draw [thick, ] (0,-3.3) -- (0,3.3);
	\draw (0,0) --  node [angle] {$\frac{\pi}{2}$} (90:3)
				node[point, above right] {$ \left(0,1\right) $};
	\draw (0,0) --  node [angle] {\footnotesize{$\pi$}} (180:3)
				node[point, above left] {$ \left(-1,0\right) $};
	\draw (0,0) --  node [angle] {$\frac{3\pi}{2}$} (270:3)
				node[point, below right] {$ \left(0,-1\right) $};
	\draw (0,0) --  node [angle] {\footnotesize{$2\pi$}} (0:3)
				node[point, above right] {$ \left(1,0\right) $};
	\draw (0,0) --  node [angle] {$\frac{\pi}{4}$} (45:3)
				node [point, above right] {$ \left( \frac{\sqrt2}{2} , \frac{\sqrt2}{2}  \right) $};
	\draw (0,0) --  node [angle] {$\frac{3\pi}{4}$} (135:3)
				node [point, above left] {$ \left( -\frac{\sqrt2}{2} , \frac{\sqrt2}{2}  \right) $};
	\draw (0,0) --  node [angle] {$\frac{5\pi}{4}$} (225:3)
				node [point, below left] {$ \left( -\frac{\sqrt2}{2} , -\frac{\sqrt2}{2}  \right) $};
	\draw (0,0) --  node [angle] {$\frac{7\pi}{4}$} (315:3)
				node [point, below right] {$ \left( \frac{\sqrt2}{2} , -\frac{\sqrt2}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{\pi}{6}$} (30:3)
				node [point, above right] {$ \left( \frac{\sqrt3}{2} , \frac{1}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{\pi}{3}$} (60:3)
				node [point, above right] {$ \left( \frac{1}{2} , \frac{\sqrt3}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{2\pi}{3}$} (120:3)
				node [point, above left] {$ \left( -\frac{1}{2} , \frac{\sqrt3}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{5\pi}{6}$} (150:3)
				node [point, above left] {$ \left(- \frac{\sqrt3}{2} , \frac{1}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{7\pi}{6}$} (210:3)
				node [point, below left] {$ \left(- \frac{\sqrt3}{2} , -\frac{1}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{4\pi}{3}$} (240:3)
				node [point, below left] {$ \left( -\frac{1}{2} , -\frac{\sqrt3}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{5\pi}{3}$} (300:3)
				node [point, below right] {$ \left( \frac{1}{2} , -\frac{\sqrt3}{2}  \right) $};
	\draw (0,0) --  node [near end, angle] {$\frac{11\pi}{6}$} (330:3)
				node [point, below right] {$ \left( \frac{\sqrt3}{2} , -\frac{1}{2}  \right) $};

	\foreach \n in {1,2,3,4}
		\foreach \t in {0,30,45,60}
			\fill (\n*90+\t:3) circle (0.03cm);
%	\foreach \t in {30,45,60, 120,135,150, 210,225,240, 300,315,330}
%		\node [font=\tiny, fill=white,inner sep=1pt] at (\t:.75) {$ \t\degree $};
\end{tikzpicture}

\end{document}

As a sidenote, I am really pleased that WordPress’s code tags seem to have improved greatly since the last time I tried to use them.  Never mind.  It’s better than it was, but it’s changing < and > to < and >.  And it took the away entirely.  For the actual code, you can check out the versions on sharelatex, as well as this document, that has them both embedded in it.  (You don’t need a ShareLaTeX account to access these links, but if you’d like to sign up for one, please use this referral link, which lets me earn points toward referral bonuses. Thanks!)

TikZ is the Bestest Thing Ever (or, A Personal History of Creating Math Documents)

I resisted learning LaTeX for awhile.  It wasn’t that I felt like it was too complicated (heck, I’m someone who taught myself Python mostly so I could make my media center do exactly what I wanted it to), but in my Master’s program it was almost discouraged by faculty (bizarre I know, I still don’t understand that).  Also, after years of administrative work, I was familiar enough with the advanced features of Word that I could layout my handouts exactly how I wanted without thinking to hard about it, which was a very good thing, because it allowed me to focus on the content of what I was creating.  I also used Adobe Illustrator, combined with the Mac graphing calculator program Grapher to make whatever graphics I needed.  I actually got really good at creating graphics I was happy with, but it was incredibly time-consuming.  I also wrote a test generator for multiple choice tests, which swapped around the order of the multiple choice answers (for those of you that teach classes of reasonable size, that may seem unnecessary, but trust me when you’re teaching five classes of fifty in extraordinarily crowded rooms it matters a lot).

Of course, since I was using Word, I used MathType (the professional version of equation editor) to typeset the math.  But then the mac version of Office 2008 eliminated VBA. It was fine at first– I just stuck with 2004.  For a long time.  Eventually it seemed annoying and sluggish, especially once I upgraded the OS, but I needed VBA for the MathType and for the test generator (not to mention a bunch of other macros I wrote to make my life easier).  And eventually the compatibility issues were fixed, and at the end of 2010, Office 2011 came out.

But then there were problems.  The most serious one was that equations that showed up fine on screen printed as white space.  During final exams for the Fall of 2010, I had a pretty serious respiratory infection (not uncommon for me) but I was pushing through it (also not uncommon), and I did not proofread the printed version of the test very carefully.  On a test with forty questions, six or seven equations were missing.  Missing!  On a final exam!  I managed to figure out what needed to be there for the most part, and had students make corrections to their exams.  It came out alright in the end, but it still was a disaster.  I felt betrayed by MathType.

And so I started thinking more about latex.  It had occurred to me in the past that I would be able to write a test generator in Python using latex (and that I could really do a lot more with Python and latex than with VBA and MathType).  And, as with most major lifestyle changes (yes, I called changing how I make documents for my classes a major lifestyle change), it bubbled around in the back of my mind for a long time before I did anything about it.

It was daunting at first, especially since I am very particular (much more so than I need to be, I admit) about the way my documents look.  Obsessive even.  And TexShop… well, it worked just fine.  But when my workflow would spiral into tweak/typeset/judge/tweak/typeset/judge/tweak/etc/etc/etc…  it got to be annoying.  It doesn’t take that long to compile the sorts of documents I was working on, but it was long enough to be irritating when you add it all up.  I tried a few other applications, including TextMate, which is what I use for almost everything else that’s text-based.  But still you have the tweak/recompile/tweak/recompile/tweak/recompile cycle.

Enter Latexian.

This was a total game-changer for me.  Latexian is a latex editor with many features that I would except in any IDE: it’s got basic syntax coloring (TextMate’s was more customizable, but that’s not a major thing for me), a spell-checker that ignores latex commands (very necessary), decent code completion, and the ability to assign shortcuts to paste in frequently used code.  But all that has nothing to do with why I love this application.  I’m all about the Live Preview panel.

I make my changes, and they’re reflected in the panel to the right.  Bam!  This may not be as big a deal to anyone else (I’m honestly a little disappointed that none of my real-life mathy friends find this as wonderful as I do– although one of them said he would switch if it were free, but he doesn’t believe in paying for software) but it brings joy to my heart.  Lots and lots of joy from a $10 application.  Totally worth it.

So I switched wholeheartedly to creating documents in latex.

There have been a few challenges (especially with formatting tables) but I used Python to write a function that would take whatever strings I had, and build them into a table.  This came in very handy, since I was constantly creating handouts of problem sets for my Pre-Cal class, and I needed a quick way to write problems, switch the order around until I was happy, and then arrange them in a table for the document.

The other major challenge was creating and editing graphics until I was happy with them.  At first, I was using the same process to create graphics as before (Illustrator and Grapher), but that’s a very time-consuming way to do things.  I looked into other more TeX-y ways to create graphics, including Asymptote, which is what my colleagues use, but I found that unsatisfying.  It wasn’t really faster (although that’s mostly because I was used to my earlier method, and I had a learning curve with Asymptote) and I couldn’t get things to look exactly like I wanted them to.  And of course then you’ve got the revise and recompile issue again.  You can embed asymptote code into a latex document, but I couldn’t get that to work with Latexian (and no way was I going to give up my new favorite toy!) and then I discovered TikZ.

I can create graphics embedded in my latex document (which makes the documents MUCH easier to share, by the way) that show up perfectly and immediately in my preview panel.  Woo!  It’s a dream come true (at least for those who dream geeky math-graphics dreams like me).  And I’ve got my graphics looking exactly like I want them to.

So I’m posting some examples.  Each example below requires
\usepackage{tikz}
in the preamble. Some of the examples also require other preamble code, which I’ve noted below.

\begin{tikzpicture} [domain=-5:5, scale=0.65, baseline=0, >=stealth]
\draw[step=1cm,very thin] (-5,-5) grid (5,5);
    \draw [thick] (-5,0) -- (5,0);
    \draw [thick] (0,-5) -- (0,5);
    \draw[ultra thick, smooth] plot ( \x , {4.0/(1.0*(\x)^2 + 1.0)});
    \draw [ultra thick, dashed] (-5,0) -- (5,0);
    \filldraw [fill=white,draw=black,thick] (0.500,3.200) circle (1.7mm);
    \filldraw [fill=white,draw=black,thick] (1.500,1.231) circle (1.7mm);
    \filldraw [fill=white,draw=black,thick] (2.500,0.552) circle (1.7mm);
    \filldraw [fill=white,draw=black,thick] (3.500,0.302) circle (1.7mm);
    \draw [ultra thick, ->] (-5,0.154) -- (-5.1,0.148);
    \draw [ultra thick, ->] (5,0.154) -- (5.1,0.148);
    \draw (0,-5) node[below] {$f_2(x) = \frac{4 \left(x -\frac{1}{2}\right) \left(x -\frac{3}{2}\right) \left(x -\frac{5}{2}\right) \left(x -\frac{7}{2}\right)} {\left(x -\frac{1}{2}\right) \left(x -\frac{3}{2}\right) \left(x -\frac{5}{2}\right) \left(x -\frac{7}{2}\right)\left(x^2+1\right)} $};
\end{tikzpicture}

In the preamble:
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.3}
\usepgfplotslibrary{polar}

In the body:
\begin{tikzpicture} [baseline=4cm]
\begin{polaraxis}[ytick={0,1,...,20}, yticklabels={,,,3,,,6,,}, xticklabels={,, $\frac{\pi}{6}$, $\frac{\pi}{3}$, $\frac{\pi}{2}$, $\frac{2\pi}{3}$, $\frac{5\pi}{6}$, $\pi$, $\frac{7\pi}{6}$, $\frac{4\pi}{3}$, $\frac{3\pi}{2}$, $\frac{5\pi}{3}$,$\frac{11\pi}{6}$,}]
\addplot+[black, very thick, mark=none, domain=0:720, samples=600 ] {2-5*cos(x)};
\end{polaraxis}
\draw (3.43cm,-.7cm) node [below] {$r=2-5\cos\theta $};
\end{tikzpicture}

\newlength{\chartscale}
\setlength{\chartscale}{0.208in}
\begin{tikzpicture}[>=stealth, baseline=-0.05in]
\draw [<->, thick] (-1.25in,0) -- (1.25in,0);
\draw (-1.5in,0) node {$\displaystyle f'(x)$};
\foreach \x/\xtext in {2/nd, -1/0, -4/0, 5/0}
{    \draw [thick] (\x*\chartscale,-0.05in) -- (\x*\chartscale,0.05in);
\draw (\x * \chartscale,0) [above=.05in] node {\scriptsize{\xtext}};
\draw (\x * \chartscale,0) [below=.05in] node {\footnotesize{$\x$}};
}
\draw (-4.99*\chartscale, 0) [above=0.05in] node {\footnotesize{${}+++{}$}};
\draw (-2.49*\chartscale, 0) [above=0.05in] node {\footnotesize{${}++++{}$}};
\draw (0.4*\chartscale, 0) [above=0.05in] node {\footnotesize{${}----{}$}};
\draw (3.50*\chartscale, 0) [above=0.05in] node {\footnotesize{${}----{}$}};
\draw (5.50*\chartscale, 0) [above=0.05in] node {\footnotesize{${}+{}$}};
\end{tikzpicture}

\begin{tikzpicture} [>=stealth, baseline=0]
\draw [thick,fill=white] (0,0) circle (3cm);
\draw [thick, <->] (-3.5,0) -- (3.5,0);
\draw [thick, <->] (0,-3.5) -- (0,3.5);
\draw (0,0) --  node [fill=white] {$\frac{\pi}{4}$} (45:3);
\draw (0,0) --  node [fill=white] {$\frac{\pi}{2}$} (90:3);
\draw (0,0) --  node [fill=white] {$\frac{3\pi}{4}$} (135:3);
\draw (0,0) --  node [fill=white] {\footnotesize{$\pi$}} (180:3);
\draw (0,0) --  node [fill=white] {$\frac{5\pi}{4}$} (225:3);
\draw (0,0) --  node [fill=white] {$\frac{3\pi}{2}$} (270:3);
\draw (0,0) --  node [fill=white] {$\frac{7\pi}{4}$} (315:3);
\draw (0,0) --  node [near end, fill=white] {$\frac{\pi}{6}$} (30:3);
\draw (0,0) --  node [near end, fill=white] {$\frac{\pi}{3}$} (60:3);
\draw (0,0) --  node [near end, fill=white] {$\frac{2\pi}{3}$} (120:3);
\draw (0,0) --  node [near end, fill=white] {$\frac{5\pi}{6}$} (150:3);
\draw (0,0) --  node [near end, fill=white] {$\frac{7\pi}{6}$} (210:3);
\draw (0,0) --  node [near end, fill=white] {$\frac{4\pi}{3}$} (240:3);
\draw (0,0) --  node [near end, fill=white] {$\frac{5\pi}{3}$} (300:3);
\draw (0,0) --  node [near end, fill=white] {$\frac{11\pi}{6}$} (330:3);
\end{tikzpicture}

In the preamble:
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}

In the body:
\begin{tikzpicture} [baseline=1.2in]
\draw [thick] (1,1) -- (1,0) -- (5,0) -- (5,1) -- (6,1) -- (6,5) -- (5,5) -- (5,6) -- (1,6) -- (1,5) -- (0,5) -- (0,1) -- (1,1) ;
\draw [semithick,dashed] (1,1) -- (1,5) -- (5,5) -- (5,1) -- (1,1);
\draw [thick, decorate,decoration={brace,amplitude=10pt},xshift=0pt,yshift=2pt] (0.05,6) -- (5.95,6) node [black,midway,yshift=16pt] {\footnotesize $5$ cm};
\draw [thick, decorate,decoration={brace,amplitude=10pt},xshift=2pt] (6,5.95) -- (6,0.05) node [black,midway,xshift=26pt] {\footnotesize $5$ cm};
\end{tikzpicture}

In the preamble:
\usepackage{tikz}
\newcommand{\opendot}[2]{\filldraw [fill=white,draw=black, thick] ({#1},{#2}) circle (.13) ;}
\newcommand{\closeddot}[2]{\filldraw [fill=black,draw=black, thick] ({#1},{#2}) circle (.13) ;}

In the body:
\newlength{\graphscale}
\setlength{\graphscale}{.35cm}
\begin{tikzpicture} [domain=-10:10, scale=1, >=stealth,x=\graphscale,y=\graphscale]
\draw[step=\graphscale,very thin] (-10,-5) grid (10,8);
\draw [very thick] (-10,0) -- (10,0);
\draw [very thick] (0,-5) -- (0,8);
\draw [ultra thick] (-10,-4) -- (-6,4);
\draw [ultra thick] (0,0) arc (0:180:3 and 1);
\draw [ultra thick] (0,0) parabola (2,4) -- (5,3);
\draw [ultra thick] (5,2) -- (10,7);
\opendot{-9}{-2}
\opendot{-6}{4}
\opendot{-3}{1}
\opendot{5}{3}
\opendot{8}{5}
\closeddot{-6}{0}
\closeddot{-3}{6}
\closeddot{5}{2}
\closeddot{8}{-1}
\end{tikzpicture}

As I said, having the graphics code embedded in the document does make sharing easier.  I was planning on posting a bunch of stuff up here, just in case someone might find it useful, but apparently WordPress doesn’t trust a .tex extension.  So I’ll look around for another way to share latex documents.  Anyone know of any?