# Unable to plot function with exponentials or to find all roots [duplicate]

I am not able to

Plot[(-1)^x + 2^x - 2 x - 1, {x, -4, 4}]


directly. Some rework might be needed with complex branch cuts perhaps.

There are real roots at $x=3, x=2$. I configured this expression with the first root 3 and there are several other concomitant complex roots. It comes to me as a surprise so with the infallible Mathematica. What may be something that I miss? I wish to be able to see the plot and all roots in the domain with your help.

• What on Earth led you to believe that Mathematica is infallible? – Jason B. May 4 '16 at 14:44
• Here's a start on the roots: NSolve[(-1)^x + 2^x - 2 x - 1 == 0 && -4 < Re@x < 4 && -1 < Im@x < 1, x] – Michael E2 May 4 '16 at 17:27
• Thanks. Just wanted to read off roots from the graph.... we read them off simply as x,y components where two graphs cut, right? – Narasimham May 7 '16 at 14:14

Here you are plotting a complex function, as you know, so you need to plot the real and imaginary parts separately.

Plot[ReIm[(-1)^x + 2^x - 2 x - 1], {x, -4, 4}, Evaluated -> True] You can get some help on this from Wolfram Alpha, if you start your expression with two equal signs: This shows that you need to plot the real and imaginary parts separately.

When in doubt check for Complexes,

FunctionDomain[(-1)^x + 2^x - 2 x - 1, x, Complexes]


True

FunctionRange[(-1)^x + 2^x - 2 x - 1, x, Complexes]


-2. <= Complexes <= 4.25

ComplexExpand[(-1)^x + 2^x - 2 x - 1, x]


$e^{-\pi \Im(x)} \cos (\pi \Re(x))+i \left(e^{-\pi \Im(x)} \sin > (\pi \Re(x))+2^{\Re(x)} \sin (\log (2) \Im(x))-2 > \Im(x)\right)+2^{\Re(x)} \cos (\log (2) \Im(x))-2 \Re(x)-1$

Find Re and Im,

sol1 = ComplexExpand[Re[(-1)^x + 2^x - 2 x - 1]]


$-2 x+2^x+\cos (\pi x)-1$

sol2 = ComplexExpand[Im[(-1)^x + 2^x - 2 x - 1]]


$\sin (\pi x)$

Have a plot:

Plot[sol1 - sol2, {x, -5, 5}] And solve for roots:

eqn = sol1 - sol2


$-2 x+2^x-\sin (\pi x)+\cos (\pi x)-1$

soln = NSolve[{eqn, 2 <= x <= 4}, x, Reals]


{{x -> 2.}, {x -> 3.}}

And you can plot the Functions:

Plot[{sol1, sol2}, {x, -4, 4}] Plot[eqn, {x, -4, 4}] Nice Plot if you need to viz other roots:

Plot[{eqn, -eqn}, {x, -4, 4}] 