banner



How To Draw Functions In Latex

Saddle surface

Following on a previous web log post on drawing fractals with LaTeX, today I am going to plot functions using LaTeX. Every bit in the previous mail, let'southward showtime by preparing the LaTeX environment from scratch:

sudo apt-get install latex209-base of operations latex209-bin latexmk texlive-full texlive-math-extra texlive-extra-utils texlive-generic-extra texlive-latex-extra

The pgfplots package for plotting functions and the standalone package for displaying the graph in a single document need to be installed manually as they are non currently present in the Ubuntu repositories:

# navigate to your local texmf folder (could also exist ~/texmf or ~/.texmf) cd ~/.texmf-var # download the pgfplots package wget http://sourceforge.net/projects/pgfplots/files/pgfplots/1.7/pgfplots_1.vii.tds.zip/download # unzip it in the texmf folder unzip pgfplots_1.7.tds.zip -d . # download the standalone parcel wget  http://mirrors.ctan.org/install/macros/latex/contrib/standalone.tds.zip # unzip it in the texmf binder unzip standalone.tds.zip -d . # update the texmf folder texhash ~/.texmf-var # remove the zip files rm standalone.tds.zip pgfplots_1.7.tds.zip

To get started I am going to plot two simple functions which can be mathematically expressed every bit follows:

y = x * 10 y = x / two

The first function is a linear function whose graph is a directly line. The second i is a quadratic function whose graph is a parabola. Here is the code to plot them with LaTeX:

\documentclass[edge=2pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{certificate} \brainstorm{tikzpicture}     \brainstorm{axis}[xmax=nine,ymax=nine,samples=50,grid=major,xlabel={ten axis},ylabel={y centrality},title={Linear and Quadratic Functions}]     \addplot[blue, ultra thick](x,x*10);     \addplot[scarlet, ultra thick](ten,x/two); \end{axis} \finish{tikzpicture} \end{document}

To compile the tex file into pdf from the command line you lot can employ the latexmk utility previously installed and open up the generated file with your preferred PDF editor (I employ evince here).

latexmk -pdf plot_functions.tex evince plot_functions.pdf &

The plotted functions wait like this (and similar this in PDF):

Plotting linear and quadratic functionsThe next graph is obtained past joining a sequence of points whose coordinates on the x and y axis are clearly visible in the code (this case is adapted from the cute PGFPlots Gallery):

\documentclass[border=2pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest} \begin{document}  \begin{tikzpicture}      \brainstorm{axis}[ xlabel=Cost, ylabel=Fault]          \addplot[color=red,marker=10] coordinates {         (2,-2.8559703)          (iii,-3.5301677)          (4,-4.3050655)          (v,-5.1413136)          (6,-6.0322865)          (seven,-6.9675052)          (viii,-7.9377747)     };      \end{axis}  \end{tikzpicture}  \terminate{certificate}

Over again, I use latexmk to compile the code and evince to open up the PDF.

latexmk -pdf plot_points.tex evince plot_points.pdf &

The plotted office looks similar this (and like this in PDF):

plot pointsFinally, I'grand going to describe a saddle surface. This is an example of hyperbolic geometry, a not-Eucledian geometry where the postulate of parallel lines doesn't hold. Popular examples of hyperbolic geometry are the Pringles crisps and print works by the Dutch artist M. C. Escher. So here is the LaTeX code to generate a saddle surface:

\documentclass[border=2pt]{standalone} \usepackage{pgfplots} \pgfplotsset{compat=newest}  \pagestyle{empty}  \usepgfplotslibrary{patchplots}  \begin{document} \begin{tikzpicture}     \begin{axis}     \addplot3[patch,patch refines=3, 		shader=faceted interp, 		patch type=biquadratic]      tabular array[z expr=x^2-y^ii]     {         x  y         -two -2         2  -2         2  2         -2 2         0  -2         2  0         0  2         -2 0         0  0     };     \end{centrality} \end{tikzpicture} \cease{document}

As usual, I compile it with latexmk and open information technology with evince.

latexmk -pdf saddle.tex evince saddle.pdf &

And here is the beautiful saddle surface (and here is the associated PDF):

Saddle surface
Saddle surface

Sources:

Mihalis Tsoukalos, LaTeX: Make text cute, Linux Format 201, Summer 2015

http://pgfplots.sourceforge.cyberspace/gallery.html

Source: https://sandrocirulli.net/how-to-plot-functions-with-latex/

Posted by: sainanderser.blogspot.com

0 Response to "How To Draw Functions In Latex"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel