0
$\begingroup$

This question already has an answer here:

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.

$\endgroup$

marked as duplicate by Jason B., MarcoB, Bob Hanlon, Artes, Rahul May 4 '16 at 20:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 5
    $\begingroup$ What on Earth led you to believe that Mathematica is infallible? $\endgroup$ – Jason B. May 4 '16 at 14:44
  • 1
    $\begingroup$ 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] $\endgroup$ – Michael E2 May 4 '16 at 17:27
  • $\begingroup$ Thanks. Just wanted to read off roots from the graph.... we read them off simply as x,y components where two graphs cut, right? $\endgroup$ – Narasimham May 7 '16 at 14:14
3
$\begingroup$

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.

$\endgroup$
0
$\begingroup$

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

$\endgroup$

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