0

Here's my attempts,

\begin{document}

\begin{tikzpicture} \draw[very thin, gray!15!black, dashed] (1,0) -- (1,5.5) (5,0) --(5,5.5); \draw[thick, black!50!gray] (1,0) rectangle (2,3) (2,0) rectangle (3,4) (3,0) rectangle (4,4.6) (4,0) rectangle (5,5); \path (1,0) node[below]{$a$} (5,0) node[below]{$b$} (3,0) node[below]{ $a+k(\frac{b-a}{n})$}(3,5) node[font=\normalsize]{$f(x)$}; \draw[thick,-latex] (-0.5,0) -- (6,0); \draw[thick,-latex] (0,-0.5) -- (0,5.7); \end{tikzpicture}

The problem now is the curve.

enter image description here

Using TikZ how can I draw this?

KersouMan
  • 1,850
  • 3
  • 13
  • 15

1 Answers1

4

Here is something you can achieve by choosing a function for your curve. Then, everything is defined with respect to this function declared with the declare function key and can be changed to adapt to the needs of the user.

\documentclass{standalone}

\usepackage{tikz} \usetikzlibrary{arrows.meta} \usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[
    declare function = {localplot(\x) = sqrt(2*\x + 1);}
]

    \draw[-Latex] (-1, 0) -- (5, 0);

    \draw[
        domain  = -0.25:4.25,
        samples = 200
    ] plot ({\x}, {localplot(\x)});

    \foreach \x in {0,0.5,...,3.5} {
        \draw (\x, 0) rectangle ({\x + 0.5}, {localplot(\x)});
    }

    \draw (0, -0.2) -- (0, {localplot(4.25) + 0.1});
    \draw (4, -0.2) -- (4, {localplot(4.25) + 0.1});

    \fill (0, 0) circle (0.05)
        node[below right] {$a$};
    \fill (4, 0) circle (0.05)
        node[below left] {$b$};

    \fill (2, 0) circle (0.05)
        node[below] {$a + k\left(\frac{b - a}{n}\right)$};

\end{tikzpicture}

\end{document}

This code yields:

enter image description here

KersouMan
  • 1,850
  • 3
  • 13
  • 15