I was asked to find the integral between x = -4
and x = 4
of the intersection of y_1 = x^2
and y_2 = -x^2
. So I recreated it using LaTeX. Please consider the following MWE:
\documentclass{article}
\usepackage[spanish]{babel}
\selectlanguage{spanish}
\decimalpoint
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\usetikzlibrary{babel,arrows.meta, patterns}
\pgfplotsset{compat=1.8}
\usepackage{mathtools}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[
legend pos=outer north east,
axis lines = center,
clip=false,
label style={font=\tiny},
legend style={font=\tiny},
xticklabel style = {font=\tiny},
yticklabel style = {font=\tiny},
xlabel = $x$,
ylabel = $y$,
xmin=-4.5,
ymin=-16.5,
xmax=4.5,
ymax=20.5,
xtick={-4,4},
ytick={-16,16}
]
\addplot[thick,red,samples=60,restrict y to domain=0:16] {x*x} node[below right] {\tiny $y_1=x^2$}; % x^2
\addplot[thick,red,samples=60,restrict y to domain=-16:0] {-x*x} node[above right] {\tiny $y_2=-x^2$}; % -x^2
\addplot[thick,red,samples=60,domain=0:4,restrict y to domain=0:16,fill=gray!60] {x*x}\closedcycle; % Area in 1º C
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
I appeal to your creativity to complete the way I did for calculating the integral: integrating from x = 0
to x = 4
and the result multiplied by 4
. I would like to highlight in some way the other three sections, each one in a different quadrant of plane.
Can you think of a nice way? I am not sure about this:
I also realize that for each section I have to add an addplot
command because the parabolas are already drawn, and it is a bit redundant. Is there any easy way to simplify the code?
And finally I do not know why the line above 16
is longer than the line below -16
:
If you could fix that, it would also be fantastic! EDIT: I could solve it by changing ymin
value to ymin=-17.5
and ymax
to ymax=17.5
.
I hope good answers! :)
.