Skip to main content
1 of 4
Jasper
  • 12k
  • 2
  • 12
  • 49

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve using pgfmath or Lua?

How can I calculate or approximate the intersection(s) or lack thereof of a line and an exponential curve.

I am not interested in fudging it with the intersections library. I want to calculate or iteratively approximate the result.

I want to use pgfmath, and if that's too hard, then Lua.

\documentclass[tikz,border=1cm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw[->] (-2,0)  -- (2,0);
        \draw[->] (0,-2)  -- (0,e^2);
        \draw[domain=-2:2] plot (\x,e^\x);
        \draw[domain=-2:2] plot (\x,\x+1.5); % two intersections
        \draw[domain=-2:2] plot (\x,\x+1); % one intersection
        \draw[domain=-2:2] plot (\x,-\x+4.5); % one intersection
        \draw[domain=-2:2] plot (\x,\x); % zero intersections
        % My goal is to use pgfmath to calculate, or if 
        % necessary iteratively approximate, the intersections 
        % of these lines with the exponential curve.
        % If it is not easy in pgfmath, then I want a Lua-based solution.
    \end{tikzpicture}
\end{document}

output

Jasper
  • 12k
  • 2
  • 12
  • 49