Wednesday, April 3, 2013

tikz: Plotting Functions

Use plot (in tikz package) to draw functions in $\mathrm{\LaTeX}$.

\usepackage{tikz,amsmath}

The example below generates this graph.

\begin{tikzpicture}[scale=0.5]
\draw[->] (0,0) -- (8,0) node[right] {$x$};
\draw[->] (0,0) -- (0,10) node[above] {$f(x)$};
\draw (1.5,0) -- (1.5,0.1) node[below] {$\frac{3}{2}$};
\draw (2.25,0) -- (2.25,0.1) node[below] {$\frac{5}{2}$};
\draw[dotted] (3,9) -- (3,0)  node[below] {$3$};
\draw [domain=0:3] plot (\x,{4/3 * \x*\x*\x - 8*\x*\x+15*\x}) node[right] {$\frac{4}{3}x^3-8x^2+15x$};
\draw [domain=3:6] plot (\x,{9*exp(3-\x)}) node[right] {$9e^{3-x}$};
\end{tikzpicture}

No comments:

Post a Comment