黎曼和 - 函数在区间 [a, b] 内的区域

黎曼和 - 函数在区间 [a, b] 内的区域

我希望得到一些帮助来构造区间 [a, b] 上的函数的黎曼积分,如图所示。 在此处输入图片描述

答案1

通过库和一些随机曲线的快速而简单的方法intersections

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{backgrounds, calc, fadings, intersections}
\begin{document}
\begin{tikzpicture}[
  declare function={a=2; b=5; dx=(b-a)/10;},
  x=+5mm, y=+5mm,
  curvy/.style={thick, blue!50!green},
]
\path (right:a) coordinate (b-0)  node[below] {\strut$a$}
      (right:b) coordinate (b-10) node[below] {\strut$b$};

\draw[curvy, path fading=west] (1,1) to[out=70, in=210] (a, 2.8) coordinate (i-0);
\draw[curvy, name path=curve]  (i-0) to[out=210+180, in=175] (b, 1.4) coordinate (i-10);
\draw[curvy, path fading=east] (i-10) to[out=175+180, in=250] (6.5, 3.5);

\path[overlay, name path=vert] foreach \i in {1, ..., 9}{
  (right:a+dx*\i) coordinate (b-\i) -- +(up:5)};
\scoped[on background layer]\fill[
  name intersections={of=curve and vert, name=i},
  left color=blue!50!green, right color=blue!25!green]
  foreach \i[count=\j from 1] in {0, ..., 9}{
    let \p{L} = (i-\i), \p{R} = (i-\j), \n0={min(\y{L},\y{R})} in
    ([xshift=+.5\pgflinewidth]b-\i)
    rectangle +([xshift=+-\pgflinewidth] dx,\n0)
  };

\draw[step=1] (-1,-2pt) grid (8,2pt) node[below] at (right:8) {\strut$x$}
              (-2pt,-1) grid (2pt,5) node[left]  at (up:5)    {$y$};
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容