使用 tkz-fct 计算两个黎曼和之间的差值

使用 tkz-fct 计算两个黎曼和之间的差值

tkz-fct非常适合绘制黎曼和,但我不知道如何绘制 sup 和 inf 黎曼和之间差异的阴影区域。我对同时具有凸区域和凹区域的绘图特别感兴趣。以下是一个例子:

\documentclass{standalone}
\usepackage{tkz-fct}

\begin{document}
  \begin{tikzpicture}
    \tkzInit[xmin=0, xmax=10, ymin=-5, ymax=5]
    \tkzFct[line width=1pt, color=black, domain=0:10]{\x**(0.5) * sin(\x) + 1}
    \tkzDrawRiemannSumSup[interval=0:10, number=15]
    \tkzDrawRiemannSumInf[interval=0:10, number=15]
  \end{tikzpicture}
\end{document}

黎曼和弦

如何遮蔽 inf 和 sup 总和之间的区域,并使轴和曲线之间的矩形变得透明?

答案1

我相信下面的方法应该可以解决问题。可能有更好的方法,但我在这里所做的只是复制了您使用的两个 Riemann 命令的代码并对其进行了调整。

% arara: pdflatex
% arara: pdflatex
% arara: open
\documentclass{article}
\usepackage{tkz-fct}

\makeatletter

\def\aeDrawRiemannSumSupInfDiff{\pgfutil@ifnextchar[{%
                 \catcode`\:=12 \ae@DrawRiemannSumSupInfDiff}{\ae@DrawRiemannSumSupInfDiff[]}} 
\def\ae@DrawRiemannSumSupInfDiff[#1]{%
\begingroup
\pgfkeys{%
/tkzriemann/.cd,
interval        = 1:2,
number          = 10,
opacity         = 0.5,
line width      = 1pt}
\pgfqkeys{/tkzriemann}{#1}  
  \iftkz@init@NO%
     \FPdiv{\tkz@x@delta}{\tkz@init@xorigine}{\tkz@init@xstep}%
     \FPdiv{\tkz@y@delta}{\tkz@init@yorigine}{\tkz@init@ystep}%
  \else
     \FPset{\tkz@x@delta}{0}
     \FPset{\tkz@y@delta}{0}%
  \fi%
\FPadd\tkz@intwd{\tkz@max}{-\tkz@min}
\FPdiv\tkz@delta{\tkz@intwd}{\tkz@fct@nb}
\FPadd\tkz@fct@nb{\tkz@fct@nb}{-1}   

\begin{scope}
\foreach \i in {0,1,...,\tkz@fct@nb}{%
  \FPeval\x{(\tkz@min+i*\tkz@delta)}
  \FPeval\tkz@fx{\tkzFcta}
   \let\tkz@firstimg\tkz@fx
    \let\tkz@firstx\x 
  \FPadd\tkz@next{\x}{\tkz@delta}
  \let\tkzFctTmp\tkzFcta
  \FPset\x{\tkz@next}
  \FPeval\tkz@fxnext{\tkzFcta}
%\ifdim \tkz@fx pt > \tkz@fxnext pt\relax
% \draw[opacity=\tkz@fct@opacity,/tkzriemann/.cd,#1] (\tkz@firstx ,0 ) rectangle (\tkz@next , \tkz@firstimg/\tkz@init@ystep );
%\else 
%\draw[opacity=\tkz@fct@opacity,/tkzriemann/.cd,#1] (\tkz@firstx ,0 ) rectangle (\tkz@next , \tkz@fxnext/\tkz@init@ystep );
% \fi  
 \draw[opacity=\tkz@fct@opacity,/tkzriemann/.cd,#1] (\tkz@firstx , \tkz@fxnext/\tkz@init@ystep ) rectangle (\tkz@next , \tkz@firstimg/\tkz@init@ystep );
   }    
   \end{scope}  
\endgroup
}

\makeatother

\begin{document}

\begin{tikzpicture}
  \tkzInit[xmin=0, xmax=10, ymin=-5, ymax=5]
  \tkzFct[line width=1pt, color=black, domain=0:10]{\x**(0.5) * sin(\x) + 1}
  \aeDrawRiemannSumSupInfDiff[fill=green,interval=0:10, number=15]
  %\tkzDrawRiemannSumInf[interval=0:10, number=15]
\end{tikzpicture}



\end{document}

在此处输入图片描述

相关内容