[Tex/LaTex] Basic skills needed to draw simple functions like polynomials, trigonometry, exponential, logarithm, etc

technical-drawingtikz-pgf

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.

Best Answer

More examples using pgfplots

enter image description here

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]
\addplot [color=green,thick]  {exp(x)};
\addplot [color=purple,thick] {exp(-x)}; 
\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]
\addplot [color=red,thick]    {1/(0.5*x*(2*pi)^0.5)*exp(-ln(x)*ln(x)/0.5)};
\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]
\addplot [color=red,thick,domain=-180:180]      {sin(x)};
\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]
\addplot [color=red,thick,domain=-0.02:0.02 ]     {x*sin(1/x)};
\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]
\addplot [color=red,thick]  {10^x};
\legend{$10^x$}
\end{semilogyaxis}
\end{tikzpicture}

\vspace{3cm}

\begin{tikzpicture}
\begin{loglogaxis}[
grid=major,
xlabel=$x$,
ylabel=$y(x)$,
legend pos=north west
]
\addplot[only marks, mark size=4pt,mark=triangle,fill,black] coordinates{
(1 , 10)
(10 , 100)
(100 ,  1000)};
\legend{discrete type}
\end{loglogaxis}
\end{tikzpicture}

\end{document}