有人知道如何制作像下面这样的相对简单的图表吗?是否有某种我可以使用“模板”?我想编写我的微积分笔记,但我不知道如何制作图表。分别是左近似、右近似和中间近似。唉……
答案1
快速而肮脏:
\documentclass[tikz,border=5]{standalone}
\tikzset{declare function={y(\x)=4-\x^2;},
plot fill/.style={fill=purple!75},
plot/.style={draw=black!80, thick},
bar/.style={fill=cyan, draw=white, thick},
marking/.style={fill=cyan!50!black, draw=cyan!50!black},
axis/.style={thick, draw=black!65, stealth-stealth}
}
\begin{document}
\begin{tikzpicture}[x=1.5cm, line cap=round, line join=round]
\foreach \k [count=\z] in {0, 1/4, 1/2}{
\begin{scope}[shift=(0:\z*3)]
\path [plot fill] plot [domain=0:2] (\x,{y(\x)}) -| cycle;
\foreach \x in {0, 1/2, 1, 3/2}
\path [bar] (\x,0) |- (\x+1/2, {y(\x+\k)}) |- cycle;
\path [plot] plot [domain=0:2] (\x,{y(\x)});
\path [axis] (0,4.5) |- (2.5,0);
\foreach \t [count=\x from 0] in {0,\frac{1}{2},1,\frac{3}{2},2}
\path [axis, -] (\x/2,0) -- ++(0,-3pt) node [below] {$\t$};
\foreach \y in {0,4}
\path [axis, -] (0,\y) -- ++(-3pt, 0) node [left] {$\y$};
\foreach \x in {0, 1/2, 1, 3/2}
\path [marking] (\x+\k, {y(\x+\k)}) circle [radius=1.5pt];
\end{scope}
}
\end{tikzpicture}
\end{document}
答案2
我可以使用我的包来建议此解决方案xpicture
。您可以根据需要添加颜色,但对于更复杂的设计,请使用tikzpicture
包。
\documentclass{standalone}
\usepackage{xpicture}
\usepackage{ifthen}
\begin{document}
\newqpoly{\f}{4}{0}{-1} % Define f(x)=4-x^2
\referencesystem(0,0)(2,0)(0,1) % Change reference system to get a larger x-unit
\setlength{\unitlength}{1cm}
\renewcommand{\xunitdivisions}{2} % x-Tics at every half unit
\begin{Picture}(-1,-1)(3,5)
\cartesianaxes(-0.1,-0.1)(2.1,4.1)
\printxticlabel{0.5}{1/2}
\printxticlabel{1.5}{3/2}
\PlotFunction[20]{\f}{0}{2} % Plot f(x)
\COPY{0}{\x}
\whiledo{\lengthtest{\x pt}<2 pt}{% % Loop to plot Taylor sum
\COPY{\x}{\xzero}
\f{\xzero}{\yzero}{\Dyzero} % yzero=f(xzero)
\ADD{0.5}{\x}{\x}
\Polyline(\xzero,0)(\xzero,\yzero)(\x,\yzero)(\x,0)
}
\end{Picture}
\begin{Picture}(-1,-1)(3,5)
\cartesianaxes(-0.1,-0.1)(2.1,4.1)
\printxticlabel{0.5}{1/2}
\printxticlabel{1.5}{3/2}
\PlotFunction[20]{\f}{0}{2}
\COPY{0}{\x}
\whiledo{\lengthtest{\x pt}<2 pt}{%
\COPY{\x}{\xzero}
\ADD{0.5}{\x}{\x}
\f{\x}{\y}{\Dy} % y=f(x)
\Polyline(\xzero,0)(\xzero,\y)(\x,\y)(\x,0)
}
\end{Picture}
\begin{Picture}(-1,-1)(3,5)
\cartesianaxes(-0.1,-0.1)(2.1,4.1)
\printxticlabel{0.5}{1/2}
\printxticlabel{1.5}{3/2}
\PlotFunction[20]{\f}{0}{2}
\COPY{0}{\x}
\whiledo{\lengthtest{\x pt}<2 pt}{%
\COPY{\x}{\xzero}
\ADD{0.5}{\x}{\x}
\ADD{0.25}{\xzero}{\xm}
\f{\xm}{\ym}{\Dym} % ym=f(xm)
\Polyline(\xzero,0)(\xzero,\ym)(\x,\ym)(\x,0)
}
\end{Picture}
\end{document}