Skip to main content
removed left-over typeout
Source Link
user691586
  • 4.6k
  • 4
  • 15
\documentclass[tikz,border=1cm]{standalone}
\usepackage{xintexpr}


\xintdeffloatfunc F(t,c) := (1-t)/(c*exp(-t) - 1);
\xintdeffloatfunc G(t,d) := d + log(t);
\xintdeffloatfunc K(t,d) := (G(t,d)-1)/(1 - 1/t);
\newcommand\SolveExpEqualLin[2]{%
\begingroup
    \xintdeffloatvar u:= #1;%
    \xintdeffloatvar v:= #2;%
    % There appears to be a bug in XINT with \xintifsgnexpr
    % when used with input starting with a zero. (I was
    % skeptical but it seems to be real, I reported to maintainer
    % and I am awaiting response).
    \xintifboolexpr{u>0}
       {\SolveExpEqualLinPos}%
       {\xintifboolexpr{u<0}
             {\SolveExpEqualLinNeg}
             {\SolveExpEqualLinZero}}
\endgroup
}
% negative slope. Always exactly one root.
% Attention to computation of epsilon.  If the root is exactly zero
% we are doomed if we let it evolve to be dynamically proportional
% to the computed approximation.
% So we compute eps only at first ieration. The value is then 1/(c-1)
% which is not zero.
\newcommand\SolveExpEqualLinNeg{%
    \xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);% c<0
    \xintdeffloatvar tn:= F(0, c);%
    % it turned out that it was too small here with 5e-16
    % because it could be that iteration fell into
    % infinite loop ...6-->...8-->...6-->..6 etc as last
    % significant figure.  So let's be more cautious.
    \xintdeffloatvar eps:=abs(tn) * 1e-15;% attention to sign...
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn := new;\iftrue}
    \repeat
    \xdef\roots{\xintfloateval{tn-delta}}%
}

% zero slope
\newcommand\SolveExpEqualLinZero{%
    \xintifboolexpr{v<=0}{\xdef\roots{}}{\xdef\roots{\xintfloateval{log(v)}}}%
}

% positive slope
\newcommand\SolveExpEqualLinPos{%
    \xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);%
    \xintdeffloatvar d:= log(u) + delta;%
    \xintifboolexpr{d-1>1e-15}
      {\SolveExpEqualLinPosTwo}
      {\xintifboolexpr{d-1<-1e-15}
           {\xdef\roots{}}%
           {\xdef\roots{\xintfloateval{1 - delta}}}%
      }%
}

% positive slope, two roots
\newcommand\SolveExpEqualLinPosTwo{%
    \xintdeffloatvar tn:=1/(c-1);%
    \xintdeffloatvar eps:=tn * 1e-15;%
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn:=new;\iftrue}
    \repeat
    \xintdeffloatvar w_1 := tn;%
    %
    \xintdeffloatvar tn:=d;%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar eps:=tn* 1e-15;% careful not too small
    \xintloop
    \xintdeffloatvar new:=K(tn, d);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn :=new;\iftrue}%
    \repeat
    \xintdeffloatvar w_2 := tn;%
    %
    %The solutions to the equation $\exp(t) = \xintfloateval{c}t$ are
    %$t_1\approx\xintfloateval[-1]{w_1}$ and $t_2\approx\xintfloateval[-1]{w_2}$.
    \xdef\roots{\xintfloateval{w_1-delta}, \xintfloateval{w_2-delta}}%
}


\begin{document}
\begin{tikzpicture}
  \def\xmin{-0.5}
  \def\xmax{3.6}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \xintFor* #1 in {\xintSeq{3}{10}}\do{%
  \draw[domain=-0.1:\xmax,samples=2,color=gray,line width=0.1] plot (\x,{#1*\x});
  \SolveExpEqualLin{#1}{0}%
  \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}


\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=\xmin:#1,samples=2,color=blue!50,line width=0.3] plot (\x,{-\x+#1});
    \SolveExpEqualLin{-1}{#1}%
    \foreach \r in \roots { \fill[blue] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}

\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=#1:\xmax,samples=2,color=red!50,line width=0.3] plot (\x,{\x-#1});
    \SolveExpEqualLin{+1}{-#1}%
    \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }

    \typeout{x-#1, \roots}
  }
\end{tikzpicture}
\end{document}
\documentclass[tikz,border=1cm]{standalone}
\usepackage{xintexpr}


\xintdeffloatfunc F(t,c) := (1-t)/(c*exp(-t) - 1);
\xintdeffloatfunc G(t,d) := d + log(t);
\xintdeffloatfunc K(t,d) := (G(t,d)-1)/(1 - 1/t);
\newcommand\SolveExpEqualLin[2]{%
\begingroup
    \xintdeffloatvar u:= #1;%
    \xintdeffloatvar v:= #2;%
    % There appears to be a bug in XINT with \xintifsgnexpr
    % when used with input starting with a zero. (I was
    % skeptical but it seems to be real, I reported to maintainer
    % and I am awaiting response).
    \xintifboolexpr{u>0}
       {\SolveExpEqualLinPos}%
       {\xintifboolexpr{u<0}
             {\SolveExpEqualLinNeg}
             {\SolveExpEqualLinZero}}
\endgroup
}
% negative slope. Always exactly one root.
% Attention to computation of epsilon.  If the root is exactly zero
% we are doomed if we let it evolve to be dynamically proportional
% to the computed approximation.
% So we compute eps only at first ieration. The value is then 1/(c-1)
% which is not zero.
\newcommand\SolveExpEqualLinNeg{%
    \xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);% c<0
    \xintdeffloatvar tn:= F(0, c);%
    % it turned out that it was too small here with 5e-16
    % because it could be that iteration fell into
    % infinite loop ...6-->...8-->...6-->..6 etc as last
    % significant figure.  So let's be more cautious.
    \xintdeffloatvar eps:=abs(tn) * 1e-15;% attention to sign...
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn := new;\iftrue}
    \repeat
    \xdef\roots{\xintfloateval{tn-delta}}%
}

% zero slope
\newcommand\SolveExpEqualLinZero{%
    \xintifboolexpr{v<=0}{\xdef\roots{}}{\xdef\roots{\xintfloateval{log(v)}}}%
}

% positive slope
\newcommand\SolveExpEqualLinPos{%
    \xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);%
    \xintdeffloatvar d:= log(u) + delta;%
    \xintifboolexpr{d-1>1e-15}
      {\SolveExpEqualLinPosTwo}
      {\xintifboolexpr{d-1<-1e-15}
           {\xdef\roots{}}%
           {\xdef\roots{\xintfloateval{1 - delta}}}%
      }%
}

% positive slope, two roots
\newcommand\SolveExpEqualLinPosTwo{%
    \xintdeffloatvar tn:=1/(c-1);%
    \xintdeffloatvar eps:=tn * 1e-15;%
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn:=new;\iftrue}
    \repeat
    \xintdeffloatvar w_1 := tn;%
    %
    \xintdeffloatvar tn:=d;%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar eps:=tn* 1e-15;% careful not too small
    \xintloop
    \xintdeffloatvar new:=K(tn, d);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn :=new;\iftrue}%
    \repeat
    \xintdeffloatvar w_2 := tn;%
    %
    %The solutions to the equation $\exp(t) = \xintfloateval{c}t$ are
    %$t_1\approx\xintfloateval[-1]{w_1}$ and $t_2\approx\xintfloateval[-1]{w_2}$.
    \xdef\roots{\xintfloateval{w_1-delta}, \xintfloateval{w_2-delta}}%
}


\begin{document}
\begin{tikzpicture}
  \def\xmin{-0.5}
  \def\xmax{3.6}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \xintFor* #1 in {\xintSeq{3}{10}}\do{%
  \draw[domain=-0.1:\xmax,samples=2,color=gray,line width=0.1] plot (\x,{#1*\x});
  \SolveExpEqualLin{#1}{0}%
  \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}


\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=\xmin:#1,samples=2,color=blue!50,line width=0.3] plot (\x,{-\x+#1});
    \SolveExpEqualLin{-1}{#1}%
    \foreach \r in \roots { \fill[blue] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}

\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=#1:\xmax,samples=2,color=red!50,line width=0.3] plot (\x,{\x-#1});
    \SolveExpEqualLin{+1}{-#1}%
    \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }

    \typeout{x-#1, \roots}
  }
\end{tikzpicture}
\end{document}
\documentclass[tikz,border=1cm]{standalone}
\usepackage{xintexpr}


\xintdeffloatfunc F(t,c) := (1-t)/(c*exp(-t) - 1);
\xintdeffloatfunc G(t,d) := d + log(t);
\xintdeffloatfunc K(t,d) := (G(t,d)-1)/(1 - 1/t);
\newcommand\SolveExpEqualLin[2]{%
\begingroup
    \xintdeffloatvar u:= #1;%
    \xintdeffloatvar v:= #2;%
    % There appears to be a bug in XINT with \xintifsgnexpr
    % when used with input starting with a zero. (I was
    % skeptical but it seems to be real, I reported to maintainer
    % and I am awaiting response).
    \xintifboolexpr{u>0}
       {\SolveExpEqualLinPos}%
       {\xintifboolexpr{u<0}
             {\SolveExpEqualLinNeg}
             {\SolveExpEqualLinZero}}
\endgroup
}
% negative slope. Always exactly one root.
% Attention to computation of epsilon.  If the root is exactly zero
% we are doomed if we let it evolve to be dynamically proportional
% to the computed approximation.
% So we compute eps only at first ieration. The value is then 1/(c-1)
% which is not zero.
\newcommand\SolveExpEqualLinNeg{%
    \xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);% c<0
    \xintdeffloatvar tn:= F(0, c);%
    % it turned out that it was too small here with 5e-16
    % because it could be that iteration fell into
    % infinite loop ...6-->...8-->...6-->..6 etc as last
    % significant figure.  So let's be more cautious.
    \xintdeffloatvar eps:=abs(tn) * 1e-15;% attention to sign...
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn := new;\iftrue}
    \repeat
    \xdef\roots{\xintfloateval{tn-delta}}%
}

% zero slope
\newcommand\SolveExpEqualLinZero{%
    \xintifboolexpr{v<=0}{\xdef\roots{}}{\xdef\roots{\xintfloateval{log(v)}}}%
}

% positive slope
\newcommand\SolveExpEqualLinPos{%
    \xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);%
    \xintdeffloatvar d:= log(u) + delta;%
    \xintifboolexpr{d-1>1e-15}
      {\SolveExpEqualLinPosTwo}
      {\xintifboolexpr{d-1<-1e-15}
           {\xdef\roots{}}%
           {\xdef\roots{\xintfloateval{1 - delta}}}%
      }%
}

% positive slope, two roots
\newcommand\SolveExpEqualLinPosTwo{%
    \xintdeffloatvar tn:=1/(c-1);%
    \xintdeffloatvar eps:=tn * 1e-15;%
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn:=new;\iftrue}
    \repeat
    \xintdeffloatvar w_1 := tn;%
    %
    \xintdeffloatvar tn:=d;%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar eps:=tn* 1e-15;% careful not too small
    \xintloop
    \xintdeffloatvar new:=K(tn, d);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn :=new;\iftrue}%
    \repeat
    \xintdeffloatvar w_2 := tn;%
    %
    %The solutions to the equation $\exp(t) = \xintfloateval{c}t$ are
    %$t_1\approx\xintfloateval[-1]{w_1}$ and $t_2\approx\xintfloateval[-1]{w_2}$.
    \xdef\roots{\xintfloateval{w_1-delta}, \xintfloateval{w_2-delta}}%
}


\begin{document}
\begin{tikzpicture}
  \def\xmin{-0.5}
  \def\xmax{3.6}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \xintFor* #1 in {\xintSeq{3}{10}}\do{%
  \draw[domain=-0.1:\xmax,samples=2,color=gray,line width=0.1] plot (\x,{#1*\x});
  \SolveExpEqualLin{#1}{0}%
  \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}


\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=\xmin:#1,samples=2,color=blue!50,line width=0.3] plot (\x,{-\x+#1});
    \SolveExpEqualLin{-1}{#1}%
    \foreach \r in \roots { \fill[blue] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}

\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=#1:\xmax,samples=2,color=red!50,line width=0.3] plot (\x,{\x-#1});
    \SolveExpEqualLin{+1}{-#1}%
    \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }
\end{tikzpicture}
\end{document}
extend the xintexpr code to handle all cases, add plots
Source Link
user691586
  • 4.6k
  • 4
  • 15

With TikZ (general case)

The code is extended to handle all possibilities, I also declared once and for all some functions of two variables for efficiency, and was more careful in termination criterion for Newton's method. I am not nimble with TikZ and can not do easily some obvious improvements the displayed plots are in need of. Incidentally I found a bug of \xintifsgnexpr and had to renounce using it.

\documentclass[tikz,border=1cm]{standalone}
\usepackage{xintexpr} 


\xintdeffloatfunc F(t,c) := (1-t)/(c*exp(-t) - 1);
\xintdeffloatfunc G(t,d) := d + log(t);
\xintdeffloatfunc K(t,d) := (G(t,d)-1)/(1 - 1/t);
\newcommand\SolveExpEqualLin[1]\newcommand\SolveExpEqualLin[2]{%
\begingroup\long\def\STOP##1\endgroup{}%\begingroup
    \xintdeffloatvar cu:= #1;%
    \xintdeffloatvar dv:= log#2;%
    % There appears to be a bug in XINT with \xintifsgnexpr
    % when used with input starting with a zero. (cI was
    % skeptical but it seems to be real, I reported to maintainer
    % and I am awaiting response);%.
    \xintifboolexpr{c>exp(1)u>0}
       {\SolveExpEqualLinPos}%
       {\xintifboolexpr{u<0}
             {Bad\SolveExpEqualLinNeg}
 input $\xintfloateval           {c\SolveExpEqualLinZero}$}
\endgroup
}
% notnegative greaterslope. thanAlways $\expexactly one root.
% Attention to computation of epsilon.  If the root is exactly zero
% we are doomed if we let it evolve to be dynamically proportional
% to the computed approximation.
% So we compute eps only at first ieration. The value is then 1/(c-1)$,
% Aborting!\STOP}which is not zero.
\newcommand\SolveExpEqualLinNeg{%
    \xintdeffloatvar tndelta:=1= v/u;%
    \xintdeffloatvar c:= u * exp(delta);% c<0
    \xintdeffloatvar tn:= F(0, c-1);%
    % it turned out that it was too small here with 5e-16
    % because it could be that iteration fell into
    % infinite loop ...6-->...8-->...6-->..6 etc as last
    % significant figure.  So let's be more cautious.
    \xintdeffloatvar eps:=tn=abs(tn) * 5e1e-16;%15;% attention to sign...
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn := new;\iftrue}
    \repeat
    \xdef\roots{\xintfloateval{tn-delta}}%
}

% zero slope
\newcommand\SolveExpEqualLinZero{%
    \xintifboolexpr{v<=0}{\xdef\roots{}}{\xdef\roots{\xintfloateval{log(v)}}}%
}

% positive slope
\newcommand\SolveExpEqualLinPos{% 
 maybe not update eps?\xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);%
    \xintdeffloatvar d:= log(u) + delta;%
    \xintifboolexpr{d-1>1e-15}
      {\SolveExpEqualLinPosTwo}
      {\xintifboolexpr{d-1<-1e-15}
           {\xdef\roots{}}%
           {\xdef\roots{\xintfloateval{1 - delta}}}%
      }%
}

% positive slope, two roots
\newcommand\SolveExpEqualLinPosTwo{%
    \xintdeffloatvar tn,:=1/(c-1);%
    \xintdeffloatvar eps:=tn * 1e-15;%
    \xintloop
    \xintdeffloatvar new:=new=F(tn,c);%
 new * 5e \xintifboolexpr{abs(new-16;\iftruetn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn:=new;\iftrue}
    \repeat
    \xintdeffloatvar w_1 := tn;%
    %
    \xintdeffloatvar tn:=d;%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar eps:=tn* 5e1e-16;%15;% careful not too small
    \xintloop
    \xintdeffloatvar new:=K(tn, d);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         % maybe not update eps?
         {\xintdeffloatvar tn, eps :=new, new * 5e-16;\iftrue=new;\iftrue}%
    \repeat
    \xintdeffloatvar w_2 := tn;%
    %
    %The solutions to the equation $\exp(t) = \xintfloateval{c}t$ are
    %$t_1\approx\xintfloateval[-1]{w_1}$ and $t_2\approx\xintfloateval[-1]{w_2}$.
    \xdef\roots{\xintfloateval{w_1-delta}, \xintfloateval{w_2-delta}}%
\endgroup
} 


\begin{document}
\begin{tikzpicture}
  \def\xmin{-0.5}
  \def\xmax{3.6}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \xintFor* #1 in {\xintSeq{3}{10}}\do{%
  \draw[domain=-0.1:\xmax,samples=2,color=gray,line width=0.1] plot (\x,{#1*\x});
  \SolveExpEqualLin{#1}{0}%
  \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}


\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=\xmin:#1,samples=2,color=blue!50,line width=0.3] plot (\x,{-\x+#1});
    \SolveExpEqualLin{-1}{#1}%
    \foreach \r in \roots { \fill[blue] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}

\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=#1:\xmax,samples=2,color=red!50,line width=0.3] plot (\x,{\x-#1});
    \SolveExpEqualLin{+1}{-#1}%
    \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }

    \typeout{x-#1, \roots}
  }
\end{tikzpicture}
\end{document}

enter image description hereintercepts with exponential

intercepts, negative slope

intercepts, positive slope

With TikZ

I also declared once and for all some functions of two variables for efficiency.

\documentclass[tikz,border=1cm]{standalone}
\usepackage{xintexpr}

\xintdeffloatfunc F(t,c) := (1-t)/(c*exp(-t) - 1);
\xintdeffloatfunc G(t,d) := d + log(t);
\xintdeffloatfunc K(t,d) := (G(t,d)-1)/(1 - 1/t);
\newcommand\SolveExpEqualLin[1]{%
\begingroup\long\def\STOP##1\endgroup{}%
    \xintdeffloatvar c:= #1;%
    \xintdeffloatvar d:= log(c);%
    \xintifboolexpr{c>exp(1)}
         {}
         {Bad input $\xintfloateval{c}$ not greater than $\exp(1)$, Aborting!\STOP}%
    \xintdeffloatvar tn:=1/(c-1);%
    \xintdeffloatvar eps:=tn * 5e-16;%
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         % maybe not update eps?
         {\xintdeffloatvar tn, eps :=new, new * 5e-16;\iftrue}
    \repeat
    \xintdeffloatvar w_1 := tn;%
    %
    \xintdeffloatvar tn:=d;%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar eps:=tn* 5e-16;%
    \xintloop
    \xintdeffloatvar new:=K(tn, d);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         % maybe not update eps?
         {\xintdeffloatvar tn, eps :=new, new * 5e-16;\iftrue}%
    \repeat
    \xintdeffloatvar w_2 := tn;%
    %
    %The solutions to the equation $\exp(t) = \xintfloateval{c}t$ are
    %$t_1\approx\xintfloateval[-1]{w_1}$ and $t_2\approx\xintfloateval[-1]{w_2}$.
    \xdef\roots{\xintfloateval{w_1}, \xintfloateval{w_2}}%
\endgroup
}
\begin{document}
\begin{tikzpicture}
  \def\xmin{-0.5}
  \def\xmax{3.6}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \xintFor* #1 in {\xintSeq{3}{10}}\do{%
  \draw[domain=-0.1:\xmax,samples=2,color=gray,line width=0.1] plot (\x,{#1*\x});
  \SolveExpEqualLin{#1}%
  \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}
\end{document}

enter image description here

With TikZ (general case)

The code is extended to handle all possibilities, I also declared once and for all some functions of two variables for efficiency, and was more careful in termination criterion for Newton's method. I am not nimble with TikZ and can not do easily some obvious improvements the displayed plots are in need of. Incidentally I found a bug of \xintifsgnexpr and had to renounce using it.

\documentclass[tikz,border=1cm]{standalone}
\usepackage{xintexpr} 


\xintdeffloatfunc F(t,c) := (1-t)/(c*exp(-t) - 1);
\xintdeffloatfunc G(t,d) := d + log(t);
\xintdeffloatfunc K(t,d) := (G(t,d)-1)/(1 - 1/t);
\newcommand\SolveExpEqualLin[2]{%
\begingroup
    \xintdeffloatvar u:= #1;%
    \xintdeffloatvar v:= #2;%
    % There appears to be a bug in XINT with \xintifsgnexpr
    % when used with input starting with a zero. (I was
    % skeptical but it seems to be real, I reported to maintainer
    % and I am awaiting response).
    \xintifboolexpr{u>0}
       {\SolveExpEqualLinPos}%
       {\xintifboolexpr{u<0}
             {\SolveExpEqualLinNeg}
             {\SolveExpEqualLinZero}}
\endgroup
}
% negative slope. Always exactly one root.
% Attention to computation of epsilon.  If the root is exactly zero
% we are doomed if we let it evolve to be dynamically proportional
% to the computed approximation.
% So we compute eps only at first ieration. The value is then 1/(c-1)
% which is not zero.
\newcommand\SolveExpEqualLinNeg{%
    \xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);% c<0
    \xintdeffloatvar tn:= F(0, c);%
    % it turned out that it was too small here with 5e-16
    % because it could be that iteration fell into
    % infinite loop ...6-->...8-->...6-->..6 etc as last
    % significant figure.  So let's be more cautious.
    \xintdeffloatvar eps:=abs(tn) * 1e-15;% attention to sign...
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn := new;\iftrue}
    \repeat
    \xdef\roots{\xintfloateval{tn-delta}}%
}

% zero slope
\newcommand\SolveExpEqualLinZero{%
    \xintifboolexpr{v<=0}{\xdef\roots{}}{\xdef\roots{\xintfloateval{log(v)}}}%
}

% positive slope
\newcommand\SolveExpEqualLinPos{% 
    \xintdeffloatvar delta:= v/u;%
    \xintdeffloatvar c:= u * exp(delta);%
    \xintdeffloatvar d:= log(u) + delta;%
    \xintifboolexpr{d-1>1e-15}
      {\SolveExpEqualLinPosTwo}
      {\xintifboolexpr{d-1<-1e-15}
           {\xdef\roots{}}%
           {\xdef\roots{\xintfloateval{1 - delta}}}%
      }%
}

% positive slope, two roots
\newcommand\SolveExpEqualLinPosTwo{%
    \xintdeffloatvar tn:=1/(c-1);%
    \xintdeffloatvar eps:=tn * 1e-15;%
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn:=new;\iftrue}
    \repeat
    \xintdeffloatvar w_1 := tn;%
    %
    \xintdeffloatvar tn:=d;%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar eps:=tn* 1e-15;% careful not too small
    \xintloop
    \xintdeffloatvar new:=K(tn, d);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         {\xintdeffloatvar tn :=new;\iftrue}%
    \repeat
    \xintdeffloatvar w_2 := tn;%
    %
    %The solutions to the equation $\exp(t) = \xintfloateval{c}t$ are
    %$t_1\approx\xintfloateval[-1]{w_1}$ and $t_2\approx\xintfloateval[-1]{w_2}$.
    \xdef\roots{\xintfloateval{w_1-delta}, \xintfloateval{w_2-delta}}%
} 


\begin{document}
\begin{tikzpicture}
  \def\xmin{-0.5}
  \def\xmax{3.6}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \xintFor* #1 in {\xintSeq{3}{10}}\do{%
  \draw[domain=-0.1:\xmax,samples=2,color=gray,line width=0.1] plot (\x,{#1*\x});
  \SolveExpEqualLin{#1}{0}%
  \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}


\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=\xmin:#1,samples=2,color=blue!50,line width=0.3] plot (\x,{-\x+#1});
    \SolveExpEqualLin{-1}{#1}%
    \foreach \r in \roots { \fill[blue] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}

\begin{tikzpicture}
  \def\xmin{-3}
  \def\xmax{1.5}
  \def\step{0.25}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \edef\tmp{\xinteval{\xmin..[\step]..\xmax}}
  \xintFor #1 in {\tmp}\do{%
    \draw[domain=#1:\xmax,samples=2,color=red!50,line width=0.3] plot (\x,{\x-#1});
    \SolveExpEqualLin{+1}{-#1}%
    \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }

    \typeout{x-#1, \roots}
  }
\end{tikzpicture}
\end{document}

intercepts with exponential

intercepts, negative slope

intercepts, positive slope

add Tikz picture
Source Link
user691586
  • 4.6k
  • 4
  • 15

With TikZ

I also declared once and for all some functions of two variables for efficiency.

\documentclass[tikz,border=1cm]{standalone}
\usepackage{xintexpr}

\xintdeffloatfunc F(t,c) := (1-t)/(c*exp(-t) - 1);
\xintdeffloatfunc G(t,d) := d + log(t);
\xintdeffloatfunc K(t,d) := (G(t,d)-1)/(1 - 1/t);
\newcommand\SolveExpEqualLin[1]{%
\begingroup\long\def\STOP##1\endgroup{}%
    \xintdeffloatvar c:= #1;%
    \xintdeffloatvar d:= log(c);%
    \xintifboolexpr{c>exp(1)}
         {}
         {Bad input $\xintfloateval{c}$ not greater than $\exp(1)$, Aborting!\STOP}%
    \xintdeffloatvar tn:=1/(c-1);%
    \xintdeffloatvar eps:=tn * 5e-16;%
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         % maybe not update eps?
         {\xintdeffloatvar tn, eps :=new, new * 5e-16;\iftrue}
    \repeat
    \xintdeffloatvar w_1 := tn;%
    %
    \xintdeffloatvar tn:=d;%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar eps:=tn* 5e-16;%
    \xintloop
    \xintdeffloatvar new:=K(tn, d);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         % maybe not update eps?
         {\xintdeffloatvar tn, eps :=new, new * 5e-16;\iftrue}%
    \repeat
    \xintdeffloatvar w_2 := tn;%
    %
    %The solutions to the equation $\exp(t) = \xintfloateval{c}t$ are
    %$t_1\approx\xintfloateval[-1]{w_1}$ and $t_2\approx\xintfloateval[-1]{w_2}$.
    \xdef\roots{\xintfloateval{w_1}, \xintfloateval{w_2}}%
\endgroup
}
\begin{document}
\begin{tikzpicture}
  \def\xmin{-0.5}
  \def\xmax{3.6}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \xintFor* #1 in {\xintSeq{3}{10}}\do{%
  \draw[domain=-0.1:\xmax,samples=2,color=gray,line width=0.1] plot (\x,{#1*\x});
  \SolveExpEqualLin{#1}%
  \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}
\end{document}

enter image description here

With TikZ

I also declared once and for all some functions of two variables for efficiency.

\documentclass[tikz,border=1cm]{standalone}
\usepackage{xintexpr}

\xintdeffloatfunc F(t,c) := (1-t)/(c*exp(-t) - 1);
\xintdeffloatfunc G(t,d) := d + log(t);
\xintdeffloatfunc K(t,d) := (G(t,d)-1)/(1 - 1/t);
\newcommand\SolveExpEqualLin[1]{%
\begingroup\long\def\STOP##1\endgroup{}%
    \xintdeffloatvar c:= #1;%
    \xintdeffloatvar d:= log(c);%
    \xintifboolexpr{c>exp(1)}
         {}
         {Bad input $\xintfloateval{c}$ not greater than $\exp(1)$, Aborting!\STOP}%
    \xintdeffloatvar tn:=1/(c-1);%
    \xintdeffloatvar eps:=tn * 5e-16;%
    \xintloop
    \xintdeffloatvar new:=F(tn,c);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         % maybe not update eps?
         {\xintdeffloatvar tn, eps :=new, new * 5e-16;\iftrue}
    \repeat
    \xintdeffloatvar w_1 := tn;%
    %
    \xintdeffloatvar tn:=d;%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar tn:=G(tn, d);%
    \xintdeffloatvar eps:=tn* 5e-16;%
    \xintloop
    \xintdeffloatvar new:=K(tn, d);%
    \xintifboolexpr{abs(new-tn)<eps}
         {\iffalse}%
         % maybe not update eps?
         {\xintdeffloatvar tn, eps :=new, new * 5e-16;\iftrue}%
    \repeat
    \xintdeffloatvar w_2 := tn;%
    %
    %The solutions to the equation $\exp(t) = \xintfloateval{c}t$ are
    %$t_1\approx\xintfloateval[-1]{w_1}$ and $t_2\approx\xintfloateval[-1]{w_2}$.
    \xdef\roots{\xintfloateval{w_1}, \xintfloateval{w_2}}%
\endgroup
}
\begin{document}
\begin{tikzpicture}
  \def\xmin{-0.5}
  \def\xmax{3.6}

  \draw[->] (\xmin,0) -- (\xmax,0);
  \draw[->] (0,-0.2) -- (0,{exp(\xmax)});
  \draw[domain=\xmin:\xmax,samples=200] plot (\x,{exp(\x)});

  \xintFor* #1 in {\xintSeq{3}{10}}\do{%
  \draw[domain=-0.1:\xmax,samples=2,color=gray,line width=0.1] plot (\x,{#1*\x});
  \SolveExpEqualLin{#1}%
  \foreach \r in \roots { \fill[red] (\r,{exp(\r)}) circle (1.2pt); }
  }

\end{tikzpicture}
\end{document}

enter image description here

Fix a math typo in first paragraph
Source Link
user691586
  • 4.6k
  • 4
  • 15
Loading
add numerical example
Source Link
user691586
  • 4.6k
  • 4
  • 15
Loading
added 28 characters in body
Source Link
taiwan12
  • 3.3k
  • 10
  • 58
Loading
added mathematical treatise
Source Link
user691586
  • 4.6k
  • 4
  • 15
Loading
added a comment
Source Link
user691586
  • 4.6k
  • 4
  • 15
Loading
Source Link
user691586
  • 4.6k
  • 4
  • 15
Loading