Showing posts with label tikz. Show all posts
Showing posts with label tikz. Show all posts

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}

Monday, November 12, 2012

LyX Goes With Tikz

To load tikz package, just like all the other $\mathrm{\LaTeX}$ packages, try set $\mathrm{\LaTeX}$ preamble under Lyx > Document > Settings > LaTeX Preamble, put
\usepackage{tikz}
And in LyX, Press Ctrl + L to insert TeX/LaTeX code. e.g.
\begin{tikzpicture}[thick,minimum size=2.3cm]
\path (0,0) 
 (0.8,1) node (c) [circle,fill=red,fill opacity=0.5]{}
 (-0.8,1) node (b) [circle,fill=green,fill opacity=0.5]{}
 (0,-0.4) node (a) [circle,fill=blue,fill opacity=0.5]{};
\path (0,-0.4) node (a1) {$C$}
      (-0.8,1) node (b1) {$B_0$}
      (0.8,1) node (c1) {$A$};
\end{tikzpicture}
And finally, use File > Export -> PDF (pdfLaTeX).