# Basic skills needed to draw simple functions like polynomials, trigonometry, exponential, logarithm, etc

I am really new to graphics in LaTeX, I have understand the skills needed to draw basic straight lines and circles; I am now learning how to make simple functions like polynomials, trigonometric, exponential, logarithm, etc. I am new to this site, so apologize if a similar question had been asked.

The book that I am currently using is The Not So Short Introduction to LaTeX2e, the wikibook, but they all mention the Bezier curve. I understand the basic idea of the Bezier curve through this website http://pomax.github.io/bezierinfo/. But it is still doesn't make my graph drawing easy. Those books that I am reading do not seem to teach us how to find the control points when drawing the Bezier curves.

My questions are:

1. Are there any quick ways to draw the Bezier curve without calculating the control points. Is it a must for us to calculate the control points in order to draw a Bezier curve, or do we do it by trial-and-error?

2. Besides using the Bezier curve, is there any simpler method to draw simple functions for example the command \drawsin(x^2) or something like that or any other methods?

3. I have also read about the TikZ picture environment, but it doesn't seem to be any simpler? What are the advantages and disadvantages of using TikZ compared to Bezier curve? Can we draw simple functions like polynomials using TikZ?

4. It is possible to show me the code (using any methods) needed to draw a very basic graph like y=x^2 including the documentclass and appropriate packages. I apologise I had not made any useful attempt because this is really new to me.

I am trying to make some notes for my students about functions so I need a quick and neat way to draw graphs. I appreciate any help and explanation.

More examples using pgfplots Code

\documentclass[twocolumn]{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz,xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{tikzpicture}
\begin{axis}[domain=-4:4,
restrict y to domain=0:4,
samples=100,
grid=major,smooth,
xlabel=$x$,
ylabel=$y(x)$,
legend pos=north west]
\legend{$e^x$, $e^{-x}$}
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[domain=0.001:6,
samples=50,
grid=major,smooth,
xlabel=$x$,
ylabel=$y(x)$,
legend pos=north east]
\legend{${\frac{1}{(0.5x(2\pi)^{0.5})}e^{-\frac{\ln(x)\ln(x)}{0.5}}}$}
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
samples=100,
restrict y to domain=-4:4,
grid=major,smooth,
xlabel=$x$,
ylabel=$y(x)$,
legend pos=north east]
\legend{$sin(x)$,$x*sin(1/x)$}
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
samples=200,
restrict y to domain=-1:1,
grid=major,
xlabel=$x$,
ylabel=$y(x)$,
legend pos=north east]
\legend{$x*sin(1/x)$}
\end{axis}
\end{tikzpicture}

\vspace{2cm}

\begin{tikzpicture}
\begin{semilogyaxis}[
log basis y=10,
grid=major,smooth,
xlabel=$x$,
ylabel=$y(x)$,
legend pos=north east]
\legend{$10^x$}
\end{semilogyaxis}
\end{tikzpicture}

\vspace{3cm}

\begin{tikzpicture}
\begin{loglogaxis}[
grid=major,
xlabel=$x$,
ylabel=$y(x)$,
legend pos=north west
]
(1 , 10)
(10 , 100)
(100 ,  1000)};
\legend{discrete type}
\end{loglogaxis}
\end{tikzpicture}

\end{document}


Plotting is an easy task for PSTricks.

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot}
\psset
{
xunit=\pstRadUnit,% 3 cm represents π = 3.1415926535
algebraic=true,% infix notation enabled
plotpoints=100,% default 50
}
\begin{document}
\begin{pspicture}(0,-2)(6,2)
\psplot{0}{TwoPi}{2*sin(2*x)}
\end{pspicture}
\end{document} Since you're new to LaTeX and "...need a quick and neat way to draw graphs" you're probably better off using a tool that generates LaTeX quality graphs while avoiding the LaTeX code. This site will do that. Type in the function(s) and plotting parameters and after pressing preview, you get the graph. When you've got the picture you want, just download the picture in 1 of many formats which can then be inserted into your LaTeX document. In addition to the standard 2D graphs there's a tab for producing parametric, polar, implicit, 3D graphs and more. I'm much more fluent in the MetaPost and Asymptote languages, but it seems you are better up with tikz, and in that case the hobbypackage is the most direct answer to your first question. It implements Hobby's algorithm for tikz: this algorithm allows to compute (third-order) Bézier curves without specifying the control points, which Tikz is not able to do on its own. Hobby's algorithm was designed by John Hobby, first for use in Knuth's Metafont drawing-fonts program, and later for Hobby's own Metafont-inspired MetaPost drawing program. Asymptote also uses it and even extended it for 3D drawings.

A short example of the Hobby package, picked up from its documentation:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{hobby}
\begin{document}
\begin{tikzpicture}[scale =.5]
\draw (0, 0) to [curve through = {(6, 4) .. (4, 9 ) .. (1, 7)}] (3, 5);
\end{tikzpicture}
\end{document} 