[Tex/LaTex] Graphics: Area between curves

tikz-pgf

I'm currently trying to figure out how to create certain graphics containing two curves and shaded the area between them:

enter image description here

enter image description here

with tikz and pgftools. In the first drawing the curves are: f(x)=1/2*x^2-2*x+5 and g(x)=-1/10*x^2+2 and a=1, b=4. In the second one the curves could be f(x)=-1/6*x^2+2, g(x)=1/4*x^2 with x_1=-2.19 and x_2=2.19.

I've read through several threads here but I can't seem to figure out what the code could be so I hope you can help me to deliver my course some nice graphics 🙂

Best Answer

With recent (v1.10) fillbetween pgfplotslibrary and taking a look at pgfplots documentation or suggested answers in comments, it's easy to draw something like

enter image description here

enter image description here

with next code:

\documentclass[border=3mm,tikz]{standalone}
\usepackage{pgfplots}

\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

\begin{document}

\begin{tikzpicture}
\begin{axis}[axis lines=middle,
            xlabel=$x$,
            ylabel=$y$,
            enlargelimits,
            ytick=\empty,
            xtick={1,4},
            xticklabels={a,b}]
\addplot[name path=F,blue,domain={-.2:5}] {0.5*x^2-2*x+5} node[pos=.8, above]{$f$};

\addplot[name path=G,green,domain={-.2:5}] {-0.1*x^2+2}node[pos=.1, below]{$g$};

\addplot[pattern=north west lines, pattern color=brown!50]fill between[of=F and G, soft clip={domain=1:4}]
;
\node[coordinate,pin=30:{$A$}] at (axis cs:3.8,3){};

\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[axis lines=middle,
            xlabel=$x$,
            ylabel=$y$,
            enlargelimits,
            ytick=\empty,
            xtick={-2.19,2.19},
            xticklabels={$x_1$,$x_2$}]
\addplot[name path=F,blue,domain={-4:4}] {-(1/6)*x^2+2} node[pos=1, below]{$f$};

\addplot[name path=G,green,domain={-4:4}] {0.25*x^2}node[pos=1, above]{$g$};

\addplot[pattern=north west lines, pattern color=brown!50]fill between[of=F and G, soft clip={domain=-2.19:2.19}]
;
\node[coordinate,pin=60:{$A$}] at (axis cs:1.1,1.6){};

\end{axis}
\end{tikzpicture}
\end{document}