I'm interested in the intersection points of two functions: $y=r+x$, where $r$ is the constant, and $y=ln(1+x)$. The following code plots the two intersection points for different (negative values) of $r$ correctly and as expected:

pts = Quiet[Solve[y == r + x && y == Log[1 + x], {x, y}]];
Graphics[Point[{x, y} /. pts], PlotRange -> {{-1, 4}, {-3, 2}}, FrameLabel -> {x, y}, Frame -> True],
{r, -2, 0}]

enter image description here

However, if I try to plot data corresponding only to $x$ coordinate (or $y$) as a function of constant $r$ using a similar code (logic) I get only one intersection point (for $r<0$). The code in question is the following:

xr[r_] := Quiet[Solve[y == r + x && y == Log[1 + x], {x, y}]][[1,1](*Part: flattening and selecting x only*)
Plot[Evaluate[x /. xr[r]], {r, -2, 0}, FrameLabel -> {r, x}, Frame -> True, PlotRange -> All]

Why isn't Plot[] able to access both intersection points (it did it above)? It shows only the negative $x$ values (positive branch is omitted).

enter image description here

P.S. Solve is also unable to produce the complete result by solving $r+x-ln(1+x)=0$ for $x$, that's the reason why I'm solving the system of two equations rather than this single equation.


Since Solve uses inverse functions, not all solutions get returned. You could use Reduce instead:

Reduce[r+x == Log[1+x], x, Reals]

Reduce::useq: The answer found by Reduce contains unsolved equation(s) {0==-1+r-Log[-ProductLog[-1,Times[<<2>>]]]-ProductLog[-1,-E^Plus[<<2>>]],0==-1+r-Log[-ProductLog[Times[<<2>>]]]-ProductLog[-E^Plus[<<2>>]]}. A likely reason for this is that the solution set depends on branch cuts of Wolfram Language functions.

(r == 0 && x == 0) || (0 == -1 + r - Log[-ProductLog[-1, -E^(-1 + r)]] - ProductLog[-1, -E^(-1 + r)] && r <= 0 && x == -1 - ProductLog[-1, -E^(-1 + r)]) || (0 == -1 + r - Log[-ProductLog[-E^(-1 + r)]] - ProductLog[-E^(-1 + r)] && r <= 0 && x == -1 - ProductLog[-E^(-1 + r)])

The output is messy and generates messages, but the key is the two-arg form of ProductLog. So, a function that returns both roots is:

f[r_] := -1 - ProductLog[{0, -1}, -Exp[-1 + r]]



{-0.818943, 1.98289}

  • $\begingroup$ Thank you Carl! Reduce[] did indeed generate the correct results. If it's not a bother, I still don't understand one thing, Solve[] seemed to generate both real roots inside the Manipulate[] function in my first code snippet. Why can't it do it in the second code example? '{x, y} /. pts' replacement seems to somehow help the situation in the first example. $\endgroup$ – Dmitri Nov 30 '18 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.