2

I am trying to draw the following regionenter image description here

The best i can do is the following code:

\begin{figure}[H]
\begin{center}
    \begin{tikzpicture}
        \begin{axis}
        [   
        axis lines = middle,
        xlabel={$x$}, 
        ylabel={$y$},
        xmin=-1, xmax=2, ymin=0, ymax=3,
        xmajorticks=false
        ]
        \addplot[smooth, thick, samples=200, name path=curve1] {1/(2*x)};
        \addplot[smooth, thick, samples=200, name path=curve2] {1/x};
        \addplot[smooth, thick, samples=200, name path=curve3] {2*x^2};
        \addplot[smooth, thick, samples=200, name path=curve4] {3*x^2};

        \addplot[color=black,fill=pink,fill opacity=0.4]fill between[of=curve1 and curve2, soft clip={domain=0.5503:0.7937}];
        
        \end{axis}
        \end{tikzpicture}
\end{center}
\end{figure}

Which creates the following image:

enter image description here

Can someone help me? Because i don't know how to use the functions y=1/2x and y=1/x as a border to the shaded region.

1 Answer 1

2

This is a very hack-y solution, but it at least fills the region you're looking for. The problem is that it fills the region outside, then covers it up, which isn't quite the same thing. I will keep thinking about how to do this "right" and if I come up with something, I'll update!

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis lines = middle,
        xlabel={$x$},
        ylabel={$y$},
        xmin=-1, xmax=2, ymin=0, ymax=3,
        xmajorticks=false
    ]
    \addplot[smooth, thick, samples=200, name path=curve1] {1/(2*x)};
    \addplot[smooth, thick, samples=200, name path=curve2] {1/x};
    \addplot[smooth, thick, samples=200, name path=curve3] {2*x^2};
    \addplot[smooth, thick, samples=200, name path=curve4] {3*x^2};

    \addplot[color=black,fill=pink,fill opacity=0.4]fill between[of=curve1 and curve2, soft clip={domain=0.5503:0.7937}];
    \addplot[color=black,fill=white,fill opacity=1.0]fill between[of=curve2 and curve4, soft clip={domain=0.5503:0.8}];
    \addplot[color=black,fill=white,fill opacity=1.0]fill between[of=curve1 and curve3, soft clip={domain=0.5503:0.8}];
    \end{axis}
\end{tikzpicture}
\end{document}

resulting plot

EDIT: Here's a version that is slightly less hack-y in that it does not require any background covering-up:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        axis lines = middle,
        xlabel={$x$},
        ylabel={$y$},
        xmin=-1, xmax=2, ymin=0, ymax=3,
        xmajorticks=false
    ]
    \addplot[smooth, thick, samples=200, name path=curve1] {1/(2*x)};
    \addplot[smooth, thick, samples=200, name path=curve2] {1/x};
    \addplot[smooth, thick, samples=200, name path=curve3] {2*x^2};
    \addplot[smooth, thick, samples=200, name path=curve4] {3*x^2};

    \addplot[fill=pink,fill opacity=0.4] fill between[of=curve1 and curve4,
        soft clip={domain=0.5503:0.6299605}];
    \addplot[fill=pink,fill opacity=0.4] fill between[of=curve3 and curve4,
        soft clip={domain=0.6299605:0.69335}];
    \addplot[fill=pink,fill opacity=0.4] fill between[of=curve2 and curve3,
        soft clip={domain=0.69335:0.7937}];
    \end{axis}
\end{tikzpicture}
\end{document}
1
  • Thanks a lot! I think i've understood, now i will try to replicate this for others graphs.
    – Davide
    Commented Oct 31, 2023 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .