0

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.

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Narasimham
  • 3,160
  • 13
  • 26

2 Answers2

3

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]

Mathematica graphics

You can get some help on this from Wolfram Alpha, if you start your expression with two equal signs:

enter image description here

This shows that you need to plot the real and imaginary parts separately.

Jason B.
  • 68,381
  • 3
  • 139
  • 286
0

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}]

enter image description here

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}]

enter image description here

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

enter image description here

Nice Plot if you need to viz other roots:

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

enter image description here