
Suppose you want to connect the nodes (f) (2j-1), (g) (2j), and (h) (2j+1), where g is the middle node (as shown in the orange line above):
\draw[dashed, red] (5.6,0) node[below] {$x_{2j - 1}$} -- (f);
\draw[dashed] (6.5,0) node[below] {$x_{2j}$} -- (g);
\draw[dashed, blue] (7.4,0) node[below] {$x_{2j+1}$} -- (h);
We need a horizontal line that extends from (g) to the other two nodes. So, first "draw " a intersection of a horizontal line from (g) to the y-axis:
\path[name path=Horizontal Line at g] (g) -| (0,0);
compute the intersection of this line with the line line 6:
\path [name intersections={of=Horizontal Line at g and line 6, by={f'}}];
and label that intersection (f'). Then we just want a horizontal line from (h)
to (g) and extend it to (f'):
\draw[ultra thick, orange] (h) |- (g) -| (f');
Notes:
- The code could use some clean up, but I'll do that after I know that this is what you are looking for. It was not clear from your description what you wanted to show. I have added color to the two lines to show which ones I was trying to connect.
Code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{figure}[h!]
\caption{Composite Midpoint Rule}
\begin{tikzpicture}[scale=1.0,transform shape]
\def\basic{%
\draw[very thick, ->] (-0.3,0) -- (12,0) node[right] {$x$} coordinate (x axis);
\draw[very thick, ->] (0,-0.3) -- (0,3) node[above] {$y$};
\draw [name path=curve] (0.5,2.2) .. controls (1.5,4.4) and (9.6,0.2) .. (11.5,2.5);
\path [name path=line 1] (1.0,0) -- (1.0,3);
\path [name path=line 2] (1.5,0) -- (1.5,3);
\path [name path=line 3] (2.0,0) -- (2.0,3);
\path [name path=line 4] (2.5,0) -- (2.5,3);
\path [name path=line 5] (3.0,0) -- (3.0,3);
\path [name path=line 6] (5.6,0) -- (5.6,3);
\path [name path=line 7] (6.5,0) -- (6.5,3);
\path [name path=line 8] (7.4,0) -- (7.4,3);
\path [name path=line 9] (9.3,0) -- (9.3,3);
\path [name path=line 10] (10.1,0) -- (10.1,3);
\path [name path=line 11] (11,0) -- (11,3);
\path [name intersections={of=curve and line 1, by={a}}];
\path [name intersections={of=curve and line 2, by={b}}];
\path [name intersections={of=curve and line 3, by={c}}];
\path [name intersections={of=curve and line 4, by={d}}];
\path [name intersections={of=curve and line 5, by={e}}];
\path [name intersections={of=curve and line 6, by={f}}];
\path [name intersections={of=curve and line 7, by={g}}];
\path [name intersections={of=curve and line 8, by={h}}];
\path [name intersections={of=curve and line 9, by={i}}];
\path [name intersections={of=curve and line 10, by={j}}];
\path [name intersections={of=curve and line 11, by={k}}];
\draw[dashed] (1,0) node[below] {$x_{-1}$} -- (a);
\draw[dashed] (1.5,0) node[below] {$x_0$} -- (b);
\draw[dashed] (2,0) node[below] {$x_1$} -- (c);
\draw[dashed] (2.5,0) node[below] {$x_2$} -- (d);
\draw[dashed] (3,0) node[below] {$x_3$} -- (e);
\draw[dashed, red] (5.6,0) node[below] {$x_{2j - 1}$} -- (f);
\draw[dashed] (6.5,0) node[below] {$x_{2j}$} -- (g);
\draw[dashed, blue] (7.4,0) node[below] {$x_{2j+1}$} -- (h);
\draw[dashed] (9.3,0) node[below] {$x_{2n-1}$} -- (i);
\draw[dashed] (10.1,0) node[below] {$x_{2n}$} -- (j);
\draw[dashed] (11,0) node[below] {$x_{2n+1}$} -- (k);
\path[name path=Horizontal Line at g] (g) -| (0,0);
\path [name intersections={of=Horizontal Line at g and line 6, by={f'}}];
\draw[ultra thick, orange] (h) |- (g) -| (f');
}
\basic
%\node[above=10pt] at (k) {$\boxed{f(x)}$};
\end{tikzpicture} \end{figure}
\end{document}
Code Simplification 1:
You can use a \foreach loop to simplify your code. The second \foreach here is from Gonzalo Medina's comment -- not sure how long it would have taken me to figure that one out.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{figure}[h!]
\caption{Composite Midpoint Rule}
\begin{tikzpicture}[scale=1.0,transform shape]
\def\basic{%
\draw[very thick, ->] (-0.3,0) -- (12,0) node[right] {$x$} coordinate (x axis);
\draw[very thick, ->] (0,-0.3) -- (0,3) node[above] {$y$};
\draw [name path=curve] (0.5,2.2) .. controls (1.5,4.4) and (9.6,0.2) .. (11.5,2.5);
\path [name path=line 1] (1.0,0) -- (1.0,3);
\path [name path=line 2] (1.5,0) -- (1.5,3);
\path [name path=line 3] (2.0,0) -- (2.0,3);
\path [name path=line 4] (2.5,0) -- (2.5,3);
\path [name path=line 5] (3.0,0) -- (3.0,3);
\path [name path=line 6] (5.6,0) -- (5.6,3);
\path [name path=line 7] (6.5,0) -- (6.5,3);
\path [name path=line 8] (7.4,0) -- (7.4,3);
\path [name path=line 9] (9.3,0) -- (9.3,3);
\path [name path=line 10] (10.1,0) -- (10.1,3);
\path [name path=line 11] (11,0) -- (11,3);
% Can replace all these with a \foreach
% \path [name intersections={of=curve and line 1, by={a}}];
% ...
% \path [name intersections={of=curve and line 11, by={k}}];
%\foreach \Line in {1,...,11} {% For this to work needs some expandafter magic
% \path [name intersections={of=curve and line \Line, by={\alph{\Line}}}];
%}
\foreach \Line/\Name in {1/a, 2/b, 3/c, 4/d, 5/e, 6/f, 7/g, 8/h, 9/i, 10/j, 11/k} {%
\path [name intersections={of=curve and line \Line, by={\Name}}];
}
% Can replace all these with a \foreach
% \draw[dashed] (1,0) node[below] {$x_{-1}$} -- (a);
% ...
% \draw[dashed] (11,0) node[below] {$x_{2n+1}$} -- (k);
\foreach \point/\label in
{a/-1, b/0, c/1, d/2, e/3, f/2j-1, g/2j, h/2j+1, i/2n-1, j/2n, k/2n+1}
\draw[dashed] (\point|-0,0) node[below] {$x_{\label}$} -- (\point);
% Draw the desired lines
\path[name path=Horizontal Line at g] (g) -| (0,0);
\path[name intersections={of=Horizontal Line at g and line 6, by={f'}}];
\draw[ultra thick, orange] (h) |- (g) -| (f');
}
\basic
%\node[above=10pt] at (k) {$\boxed{f(x)}$};
\end{tikzpicture} \end{figure}
\end{document}
Code Simplification 2:
And using another \foreach you can reduce the code even further, and a few minor (my personal preferences of the arrow tips, and line styles) tweaks:

Notes:
- This was done as a separate MWE so as to make it easier to follow the evolution from the given code to this.
Code
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{figure}[h!]
\caption{Composite Midpoint Rule}
\begin{tikzpicture}[scale=1.0,transform shape]
\def\basic{%
\draw[very thick, -stealth] (-0.3,0) -- (12,0) node[right] {$x$};% x-axis
\draw[very thick, -stealth] (0,-0.3) -- (0,3) node[above] {$y$};% y-axis
\draw [name path=curve, thick, blue] (0.5,2.2) .. controls (1.5,4.4) and (9.6,0.2) .. (11.5,2.5);% curve
\foreach \x/\Point [count=\xi] in {1.0/a, 1.5/b, 2.0/c, 2.5/d, 3.0/e, 5.6/f, 6.5/g, 7.4/h, 9.3/i, 10.1/j, 11/k } {%
\path [name path global=line \xi, red] (\x,0) -- (\x,3);
\path [name intersections={of=curve and line \xi, by={\Point}}];
}%
\foreach \Line/\Name in {1/a, 2/b, 3/c, 4/d, 5/e, 6/f, 7/g, 8/h, 9/i, 10/j, 11/k} {%
\path [name intersections={of=curve and line \Line, by={\Name}}];
}
\foreach \point/\label in
{a/-1, b/0, c/1, d/2, e/3, f/2j-1, g/2j, h/2j+1, i/2n-1, j/2n, k/2n+1}
\draw[densely dotted, thick] (\point|-0,0) node[below] {$x_{\label}$} -- (\point);
% Draw the desired lines
\path[name path=Horizontal Line at g] (g) -| (0,0);
\path[name intersections={of=Horizontal Line at g and line 6, by={f'}}];
\draw[ultra thick, orange] (h) |- (g) -| (f');
}
\basic
%\node[above=10pt] at (k) {$\boxed{f(x)}$};
\end{tikzpicture} \end{figure}
\end{document}