複数の部分和を同じグラフにプロットする

複数の部分和を同じグラフにプロットする

下の図のように複数の部分和をプロットすることは可能でしょうか?

ここで、H は調和級数であり、特定の合計は線で結ばれています。残念ながら、私は tikz 初心者であり、現時点ではこの問題は私の能力の範囲外にあるようです。

答え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

ここでは部分和が 1 つしかないことに注意してください。

これは Asymptote を使用した図です。 の値が小さいほどn視覚化が良くなると思います。

実数列に対してa[i]、部分和の関連する列を計算することができるH[i]

real[] H=partialsum(a);

pointsHそして対応する点の 配列を取り、 OPが望むように(i,H[i])直線でそれらを結びますoperator--

path pH=operator--(...pointsH);

ここで、3 つのドットは...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);

関連情報