Image

Gráficos ITERATIVOS - foreach

Este video está dedicado a explicar cómo construir gráficos iterativos, como una red neuronal artificial, un polígono regular, un hilorama y una familia de funciones, todo esto, en LaTeX.

\documentclass{article}
\usepackage{tikz,color}
\usepackage{pgfplots}
\pgfplotsset{width=15cm,compat=1.12}
\begin{document}
\begin{tikzpicture}
  \foreach \i in {0,1,...,9}{
    \node at (\i,0){\i};} 
\end{tikzpicture}
\vspace{1cm}

\begin{tikzpicture}
  \foreach \i in {0,1,...,9}{
    \draw (0,0)--(\i,2);
  } 
\end{tikzpicture}
\vspace{1cm}



\begin{tikzpicture}
  \foreach \i in {-5,-4,...,5}{\draw (0,0)--(\i,2);}
  
  \foreach \j in {-5,-4,...,5}{\draw (\j,2)--(0,4);}  
\end{tikzpicture}
\vspace{1cm}

\begin{tikzpicture}
  \foreach \i in {1,2,...,10}{
    \foreach \j in {1,2,...,10}{
      \draw (\j,0)--(\i,5); 
    };  
  };  
\end{tikzpicture}
\vspace{1cm}

\begin{tikzpicture}[scale=1.5]
  \foreach \i in {-1,1}{
    \foreach \j in {-3,-2,...,3}{
      \foreach \k in {-1,0,1}{
      \draw[cyan] (0,\i)--(3,\j)--(6,\k);
        
      \fill[magenta]  (6,\k) circle (0.25);
      \node at (6,\k){$z_{\k}$};        
      };       
      \fill[red]  (3,\j) circle (0.25);
      \node[blue] at (3,\j){$y_{\j}$};        
    };
    \fill[green]  (0,\i) circle (0.25); 
    \node at (0,\i){$x_{\i}$};        
  };  

\end{tikzpicture}
\vspace{1cm}

\begin{tikzpicture}
  \foreach \i/\j in {a/30:2,b/60:2,c/90:2,d/120:2,e/150:2,f/180:2,g/210:2,h/240:2,i/270:2,j/300:2,k/330:2,l/360:2}{
    \coordinate (\i) at (\j);} 
  \draw [red] (a) -- (b) -- (c) -- (d) -- (e) -- (f) -- (g) -- (h) -- (i) -- (j) -- (k) -- (l) -- cycle;
\end{tikzpicture}
\vspace{1cm}

\begin{tikzpicture}
  \foreach \i in {1,2,...,10}{
    \foreach \j in {1,2,...,10}{
      \draw[red] ({36*\i}:2)--({36*\j}:2);
    }
  } 
\end{tikzpicture}
\vspace{1cm}

\begin{tikzpicture}
  \begin{axis}[width=10cm,
    height=10cm,
    xmin=-0.1,
    xmax=1,
    ymin=0,
    ymax=1,
    axis x line=center,
    axis y line=center,
    xlabel=$x$, 
    ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1.05)}},
    ylabel style={at={(ticklabel* cs:1.05)}}]
    \foreach \i in {0.2,0.4,...,3.6}{
      \addplot[blue!80!white,thick, samples=200,domain=-3:3]{x^\i};
    }
  \end{axis}
\end{tikzpicture}

\end{document}

        

© Profesor Favián Arenas. 2023. Diseñado por HTML Codex