% -- Preámbulo
\documentclass{article}

% idioma y entrada
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\decimalpoint

% config de página
\usepackage[
	left = 2cm, right = 2cm,
	top = 1.2cm, bottom = 1.2cm, includefoot,
]{geometry}

% para usar "subfigure"
\usepackage{caption,subcaption}
% para escribir unidades
\usepackage{siunitx}

% info. del documento
\title{
	\textbf{Día 4} \\
	\Large\textit{Gráfica de funciones 1}
}
\author{Introducción a la creación de gráfico científico con \LaTeX}
\date{13 de noviembre de 2023}

% colores
\usepackage[dvipsnames]{xcolor}

% TikZ
\usepackage{tikz}
	%para definir variables
	\usetikzlibrary{math, babel}
    \usetikzlibrary{intersections}
	
% -- Cuerpo del documento
\begin{document}
	
	% Título
	\maketitle
	
	\section{Funciones simples}

	\subsection{Funciones rectangulares $(x,y)$}

	\begin{figure}[h!]
	\centering
	
	% -- a.
	\begin{subfigure}{0.3\textwidth}
	\centering
	
	\begin{tikzpicture}[scale = 0.75]
			
		% fondo
		\fill[gray!10] 
			(-3.2,-3.2) rectangle (3.6,3.6);
			
		% plano cartesiano
        \draw[<->]
			(-3,0) -- (3,0) node[right] {$x$};
        \draw[<->]
			(0,-3) -- (0,3) node[above] {$y$};
		
		% máscara de recorte
		\clip (-3,-3) rectangle (3,3);
		
		% -- función
        \draw[smooth, dashed] plot[domain=-3:3, samples=40]
        (\x, { (\x)^2 - 1});
					
	\end{tikzpicture}
	\caption{$f(x) = x^2 - 1$}	
	\end{subfigure}
	% -- b.
	\hspace*{4mm}
	\begin{subfigure}{0.3\textwidth}
	\centering	
	
	\begin{tikzpicture}[scale = 0.75]
	
		% fondo
		\fill[gray!10] 
			(-0.4,-3.2) rectangle (6.6,3.6);
			
		% plano cartesiano
		\draw
			(0,0) -- (6,0) node[right] {$x$}
			(0,-3) -- (0,3) node[above] {$y$};
					
		\clip (0,-3) rectangle (6,3);
		
        \draw plot[domain= 0:7] (\x, {cos(3 \x r)});
		% -- función
								
	\end{tikzpicture}
		
	\caption{$f(x) = \cos(3x)$}	
	\end{subfigure}
	% -- c.
	\hspace*{4mm}
	\begin{subfigure}{0.3\textwidth}
	\centering	
	
	\begin{tikzpicture}[scale = 0.75]
		
		% fondo
		\fill[gray!10] 
			(-3.2,-3.2) rectangle (3.6,3.6);
	
		% plano cartesiano
		\draw
			(-3,0) -- (3,0) node[right] {$x$}
			(0,-3) -- (0,3) node[above] {$y$};	
			
		\clip (-3,-3) rectangle (3,3);
		% -- función
        \draw[smooth] plot[domain=-3:3, samples=200]
         (\x, {2 * exp( - 0.5 * ((\x)^2)) * sin(6*\x r)}) ;

					
	\end{tikzpicture}
		
	\caption{$2e^{-x^2/2}\sin(6x)$.}	
	\end{subfigure}
	
	\caption{}
	\end{figure}
	
	\vspace*{1cm}
	
	% ---
	\subsection{Funciones polares, $(r,\theta)$}

	\begin{figure}[h!]
	\centering
	
	% -- a.
	\begin{subfigure}{0.3\textwidth}
	\centering
	
	\begin{tikzpicture}[scale = 0.75]
			
		% fondo
		\fill[gray!10] 
			(-2.2,-3.2) rectangle (4.6,3.6);
		% plano cartesiano
		\draw
			(-2,0) -- (4,0) node[right] {$x$}
			(0,-3) -- (0,3) node[above] {$y$};

		\clip (-2,-3) rectangle (4,3);
		
		% -- función
        \draw[smooth] plot[domain=0:2*pi, samples=360] ({\x r}: {2 * cos(\x r) - 1});
					
	\end{tikzpicture}
	\caption{$f(\theta) = 2\cos(x) - 1$}	
	\end{subfigure}
	% -- b.
	\hspace*{4mm}
	\begin{subfigure}{0.3\textwidth}
	\centering	
	
	\begin{tikzpicture}[scale = 0.75]
		
		% fondo
		\fill[gray!10] 
			(-3.2,-3.7) rectangle (3.6,3.1);
		% plano cartesiano
		\draw
			(-3,0) -- (3,0) node[right] {$x$}
			(0,-3.5) -- (0,2.5) node[above] {$y$};
		
		% -- función	

        \draw[smooth] plot[domain=0:2*pi, samples=360] ({\x r}: {2*sin(3 * \x r) + 1});
					
	\end{tikzpicture}
		
	\caption{}	
	\end{subfigure}
	% -- c.
	\hspace*{4mm}
	\begin{subfigure}{0.3\textwidth}
	\centering	
	
	\begin{tikzpicture}[scale = 0.75]
	
		% fondo
		\fill[gray!10] 
			(-2.2,-2.2) rectangle (4.6,4.6);
		% plano cartesiano
		\draw
			(-2,0) -- (4,0) node[right] {$x$}
			(0,-2) -- (0,4) node[above] {$y$};	
		
		% -- función
        \draw[smooth] plot[domain=0:4*pi, samples=360] ({\x r}:
        {6 * sin(2 * \x r) * exp(-0.5 * \x)});
			
	\end{tikzpicture}
		
	\caption{$6\sin(2\theta)e^{-\theta/2}$}	
	\end{subfigure}
	
	\caption{}
	\end{figure}

	\subsection{Extras}

	\begin{figure}[h!]
	\centering
	
	\hspace*{4mm}
	\begin{subfigure}{0.3\textwidth}
	\centering	
	
	\begin{tikzpicture}[scale = 0.75]
        \tikzmath{
            \limit = 5;
            \Px = 0.2;
            function f(\x) { return (\x)^2;};
        }
	
		
		\clip (-\limit,0) rectangle (\limit,\limit);
		% -- función
        \draw[smooth, name path = parabolaA] plot[domain= (-1*\limit):\limit, samples=60] ({\x}, {f(\x)});
        \draw[smooth, name path = lineA ] (-\limit, 1.2) -- (\limit, 2.6);

        \path[name intersections = {of = lineA and parabolaA, by = {A, B} }];
        \coordinate (P) at (\Px, {f(\Px)});

        \draw[fill=gray!25] (A) -- (B) -- (P) -- cycle;
        

		% plano cartesiano
        \draw[<->, black!75]
			(-\limit,0) -- (\limit,0) node[right] {$x$};
        \draw[<->, black!75]
			(0,-0.25 * \limit) -- (0,\limit) node[above] {$y$};	

        \draw[fill=black] (A) circle (2pt);
        \draw[fill=black] (B) circle (2pt);
        \draw[fill=black] (P) circle (2pt);
			
	\end{tikzpicture}
		
	\end{subfigure}
	
	\caption{}
	\end{figure}
	
\end{document}
