1

I need to make a picture that should look like

image

I saw a similar question here but the red function line appears neither when I use --shell-escape nor when I use --enable-write18. I use TeXstudio, by the way. TikZ and pgf packages are installed.

UPD: Code which I used

    \documentclass[]{scrartcl}
\usepackage{tkz-fct}   

\begin{document}
\begin{tikzpicture}[scale=1.25]
\tkzInit[xmax=8,ymax=4]
\tkzAxeXY[ticks=false]
\tkzGrid   
\tkzFct[color = red, domain =0.125:8]{4./x}
\tkzDrawRiemannSumInf[fill=green!60,
                     opacity=.2,
                     color=green,
                     line width=1pt,
                     interval=1:8,
                     number=7] 
 \foreach \x/\t in {1.5/$a_1$,2.5/$a_2$,3.5/$a_3$,7.5/$a_7$}
 \node[green!50!black] at (\x,{4/(\x+1)-0.25}){\t};  
\end{tikzpicture}   
\end{document} 

And maybe there are some good graphic editors to draw such things by hand?

1 Answers1

3

You could use the pgfplots answer, which does not rely on external programs to calculate the function:

\documentclass{article}

\usepackage{pgfplots}

% right hand sums
\pgfplotsset{
    right segments/.code={\pgfmathsetmacro\rightsegments{#1}},
    right segments=3,
    right/.style args={#1:#2}{
        ybar interval,
        domain=#1+((#2-#1)/\rightsegments):#2+((#2-#1)/\rightsegments),
        samples=\rightsegments+1,
        x filter/.code=\pgfmathparse{\pgfmathresult-((#2-#1)/\rightsegments)}
    }
}


\begin{document}
\begin{tikzpicture}[/pgf/declare function={f=4/x;}]
\begin{axis}[
    xmin=0,xmax=8.5,ymin=0,ymax=4,
    domain=0:8.5,
    samples=100,
    axis lines=left,
    clip=false,
    restrict y to domain=0:4
]
\addplot [thick, red] {f};
\addplot [
    black!80,fill=green,opacity=.3,
    right segments=7,
    right=1:8,
] {f};

\draw [ultra thick, black!60, -latex] (axis cs:1.5,0) -- ++(0,-5ex) node [anchor=north, black] {thread 1};
\draw [ultra thick, black!60, -latex] (axis cs:2.5,0) -- ++(0,-8ex) node [anchor=north, black] {thread 2};
\draw [ultra thick, black!60, -latex] (axis cs:7.5,0) -- ++(0,-5ex) node [anchor=north, black] {thread n};
\end{axis}
\end{tikzpicture}



\end{document}
Jake
  • 232,450