Graphics, Figures & TablesError function

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jhapk
Posts: 81
Joined: Tue Apr 20, 2010 9:33 pm

Error function

Post by jhapk »

Hi,

how can I plot an error function using Tikz?

Thanks
Last edited by jhapk on Wed Jul 07, 2010 3:52 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Error function

Post by shadgrind »

For functions like erf(x) which are not one of the built-in math functions in TikZ, I use the Gnuplot TikZ terminal, which lets you export any type of plot that Gnuplot can draw into TikZ format. Read the installation instructions; on the Gnuplot end you'll need version 4.40, and on the LaTeX end you'll need to install the gnuplot-lua-tikz.sty file. After you've set it all up, you can do something like this in Gnuplot:

Code: Select all

set terminal lua tikz originreset size 5in,3in
set xlabel '$x$'
set ylabel '$y$'
set output 'erf.tex'
plot [0:pi] erf(x)
That will create a tikzpicture environment in a file called erf.tex, which you can then include in your LaTeX document. Here's a complete example:

Code: Select all

\documentclass[letterpaper]{article}
\usepackage{tikz}
\usepackage{gnuplot-lua-tikz}
\begin{document}
Here is a graph of the error function:

\begin{center}
\input{erf}
\end{center}

\end{document}
You can tweak the erf.tex file to suit your needs. I always change the numbers on the axes to math mode.
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Error function

Post by localghost »

The method introduced by shadgrind seems to me a little bit too complicated. The pgfplots package offers a very easy interface to Gnuplot.

Code: Select all

\documentclass{minimal}
\usepackage{amsmath}
\usepackage{pgfplots}

\DeclareMathOperator{\erf}{erf}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[%
      xlabel=$x$,
      ylabel=$\erf(x)$
    ]
      \addplot[smooth] gnuplot[id=erf]{erf(x)};
    \end{axis}
  \end{tikzpicture}
\end{document}
For more information refer to the package manual. Note the special remarks about the prerequisites for making Gnuplot work with this package (keyword: option -shell-escape for the compiler).


Best regards and welcome to the board
Thorsten
jhapk
Posts: 81
Joined: Tue Apr 20, 2010 9:33 pm

Re: Error function

Post by jhapk »

Thanks Thorsten,

that worked smoothly.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Error function

Post by localghost »

Now that the problem is solved, please act like you have already been directed in my last reply.
Post Reply