微分方程式 y'+2y=0 の解 y=f(x) を初期条件 f(0)=1 のもとで近似する

解1

Clear[x, y]

x[n_, k_] := N[k/n]

x[5, 3]

y[n_, k_] := N[(1 - (2/n))^k]

Clear[T]

T[n_, a_] := Table[{x[n, k], y[n, k]}, {k, 0, a*n}]

T[5, 2]

Clear[G]

G[n_, a_] := 
      ListPlot[T[n, a], PlotJoined -> True, PlotStyle -> Hue[0.6], 
        AspectRatio -> 
          Automatic, 
PlotRange -> {0, 1}]

G[3, 1];

Clear[G1]

G1[a_] := 
      Plot[Exp[-2*x], {x, 0, a}, PlotStyle -> Hue[0.0], 
        AspectRatio -> Automatic, PlotRange -> {0, 1}]

G1[1];

Show[G[3, 2], G1[2]];

Do[Show[G[n, 2], G1[2]], {n, 3, 30, 3}];

解2

Sol[n_, a_] := 
      Module[{D = {{0, 1}}, s = 1}, 
        Do[s = (1 - (2/n))^k // N; 
D = 
            Append[D, {N[k/n], s}], 
{k, 1, a*n}]; 
        D]

Sol[3, 2]

(1 - (2/3))^2 // N

ListPlot[Sol[20, 2], PlotJoined -> True];

Plot[Exp[-2 x], {x, 0, 2}];