![在同一张图上绘制多个部分和](https://linux22.com/image/421129/%E5%9C%A8%E5%90%8C%E4%B8%80%E5%BC%A0%E5%9B%BE%E4%B8%8A%E7%BB%98%E5%88%B6%E5%A4%9A%E4%B8%AA%E9%83%A8%E5%88%86%E5%92%8C.png)
答案1
以下是开始使用pgfplots
\documentclass[border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymin=0,
ymax=7,
xmin=0,
xmax=100,
domain=0:100,
samples=200,
axis lines=left,
clip=true,
clip mode=individual]
\addplot [black] {ln(x) + 1} node (plot1) {};
\node [right] at (plot1) {$\ln(n) + 1$};
\addplot [black] {ln(x) +(1/x)} node (plot2) {};
\node [right] at (plot2) {$\ln(n) + \frac{1}{n}$};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
请注意,这里只有一个部分总和。
这是使用 Asymptote 的插图。我认为较小的值n
可以提供更好的可视化效果。
对于实数序列,我们可以计算部分和的a[i]
相关序列H[i]
real[] H=partialsum(a);
然后取一组pointsH
对应点 ,然后按照 OP 的要求(i,H[i])
用直线将它们连接起来operator--
path pH=operator--(...pointsH);
其中三个点...pointsH
表示的所有点pointsH
。
完整代码
// http://asymptote.ualberta.ca/
usepackage("amsmath");
unitsize(1cm,2.5cm);
size(8cm);
import graph;
import math;
int n=10;
real[] a; a[0]=0;
for(int i=1; i<n; ++i) a[i]=1/i;
real[] H=partialsum(a);
pair[] pointsH; // points of the partial sum
for(int i=1; i<H.length; ++i) pointsH.push((i,H[i]));
path pH=operator--(...pointsH); // joining by straight segments
draw(Label("$H_n=\sum\limits_{k=1}^n\dfrac{1}{k}$",align=3E,EndPoint),pH);
real f(real x){return log(x) + 1;} // the upper function
real g(real x){return log(x) + 1/x;} // the lower function
real s=.25;
path pf=graph(f,s,n-1);
path pg=graph(g,s,n-1);
draw(Label("$1+ \ln x$",EndPoint,align=NE),pf,blue);
draw(Label("$\dfrac{1}{x}+ \ln x$",EndPoint,align=SE),pg,purple);
dot(pointsH,red);
axes("$x$","$y$");
draw((1,1)--(1,0)^^(1,1)--(0,1),dashed+gray);
label("$1$",(1,0),S);
label("$1$",(0,1),W);
//label("$1+\ln n <1+\dfrac{1}{2}+\dfrac{1}{3}+\codts + \dfrac{1}{n}<\dfrac{1}{n}+\ln n$",truepoint(S)+(0,-1));
另一种说明方式:
// http://asymptote.ualberta.ca/
usepackage("amsmath");
unitsize(1cm,3cm);
size(8cm);
import graph;
import math;
real f(real x){return log(x) + 1;} // the upper function
real g(real x){return log(x) + 1/x;} // the lower function
int n=20;
real[] h,A,B; h[0]=0; A[0]=0; B[0]=0;
for(int i=1; i<n; ++i) {
h[i]=1/i;
A[i]=f(i);
B[i]=g(i);
}
real[] H=partialsum(h);
pair[] pointsH, pointsA, pointsB; // points of the partial sum
for(int i=1; i<H.length; ++i){
pointsH.push((i,H[i]));
pointsA.push((i,A[i]));
pointsB.push((i,B[i]));
}
path pH=operator--(...pointsH); // joining by straight segments
path pA=operator--(...pointsA);
path pB=operator--(...pointsB);
draw(Label("$H_n=\sum\limits_{k=1}^n\dfrac{1}{k}$",align=3E,EndPoint),pH);
draw(Label("$\ln n+1$",align=3NE,EndPoint),pA);
draw(Label("$\ln n+\dfrac1x$",align=3SE,EndPoint),pB);
dot(pointsH,red);
dot(pointsA,blue);
dot(pointsB,purple);
axes("$x$","$y$");
draw((1,1)--(1,0)^^(1,1)--(0,1),dashed+gray);
label("$1$",(1,0),S);
label("$1$",(0,1),W);