diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /macros/latex/contrib/animate/files/exp.mp |
Initial commit
Diffstat (limited to 'macros/latex/contrib/animate/files/exp.mp')
-rw-r--r-- | macros/latex/contrib/animate/files/exp.mp | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/macros/latex/contrib/animate/files/exp.mp b/macros/latex/contrib/animate/files/exp.mp new file mode 100644 index 0000000000..85c5c42969 --- /dev/null +++ b/macros/latex/contrib/animate/files/exp.mp @@ -0,0 +1,121 @@ +% Jan Holecek, Alexander Grahn +% 2018/11/29 + +prologues:=3; +outputtemplate := "%j_%c.mps"; +outputformat := "mps"; + +verbatimtex +\documentclass{article} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +%\usepackage{lmodern} + \usepackage[tt=false]{libertine} + \usepackage[libertine]{newtxmath} +\usepackage{amsmath} +\begin{document} +etex + +e := 2.718282; +N=8; +size := 5cm; +bars := 0.5mm; +diff := 0.05; +xmin := -2; +xmax := 2; +xo := -2; +ymin := 0; +ymax := e**xmax; +xcoe := size / (xmax - xmin); +ycoe := size / (ymax - ymin); + + +pair xaxis[], yaxis[], npnt; +xaxis[1] = (xmin * xcoe, 0); xaxis[2] = (xmax * xcoe, 0); +yaxis[1] = (0, ymin * ycoe); yaxis[2] = (0, ymax * ycoe); +npnt = (xmin * xcoe, ymax * ycoe); + +picture xlabel, ylabel, elabel, nlabel[]; +xlabel = btex $x$ etex; +ylabel = btex $y$ etex; +elabel = btex $y = e^x$ etex; +nlabel[1] = btex $n = 1$ etex; +nlabel[2] = btex $n = 2$ etex; +nlabel[3] = btex $n = 3$ etex; +nlabel[4] = btex $n = 4$ etex; +nlabel[5] = btex $n = 5$ etex; +nlabel[6] = btex $n = 6$ etex; +nlabel[7] = btex $n = 7$ etex; +nlabel[8] = btex $n = 8$ etex; + + +def pnt (expr x,y)= + ( x * xcoe, y * ycoe ) +enddef; + +def exp (expr x)= + pnt (x , e**x) +enddef; + +def taylor (expr s,x)= + begingroup + save i,v,w; + v = 1; + w = 1; + for i := 1 upto s: + w := (w * (x-xo)) / i; + v := v + w; + endfor; + pnt (x , v * (e**xo)) + endgroup +enddef; + +path pexp,ptaylor[]; + +pexp = exp(xmin) +for i:=xmin+diff step diff until xmax: + .. exp(i) +endfor; + +for j:=1 upto N: + ptaylor[j] := taylor (j,xmin) + for i:=xmin+diff step diff until xmax: + .. taylor(j,i) + endfor; +endfor; + +def axis= + drawarrow xaxis[1]--xaxis[2]; + drawarrow yaxis[1]--yaxis[2]; + for k:=-1,1: + draw (k * xcoe, -bars) -- (k * xcoe, bars); + endfor; + for k:=1 upto 6: + draw (-bars, k * ycoe) -- (bars, k * ycoe); + endfor; + draw pexp withcolor red; + label.lrt (xlabel, xaxis[2]); + label.ulft (ylabel, yaxis[2]); + label.top (elabel, point (length (pexp)) of pexp); +enddef; + +path bounds; +beginfig(0); + pickup pencircle scaled 0.4mm; + axis; + bounds:=bbox currentpicture; + setbounds currentpicture to bounds; + clip currentpicture to bounds; +endfig; + +for i:=1 upto N: + beginfig(i); + pickup pencircle scaled 0.4mm; + draw ptaylor[i] withcolor blue; + label.lrt ( nlabel[i], npnt); + setbounds currentpicture to bounds; + clip currentpicture to bounds; + endfig; +endfor; + +end. |