Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Possible Duplicate:
How to plot imaginary part of a function
Plotting Complex Quantity Functions

For example, this Wolfram Alpha query shows this graph:

enter image description here

But it does not show the code for plotting it in Mathematica. Plot[x^x, {x, -1, 1}] only plots the real values. How can I do this in Mathematica?

share|improve this question

marked as duplicate by Sjoerd C. de Vries Sep 14 '12 at 8:37

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.

1  
Try this:Plot[{Re[x^x], Im[x^x]}, {x, -1, 2}, PlotRange -> All] –  xzczd Sep 14 '12 at 4:39
    
...then there's also this... (one of the vagaries of having to choose a "principal branch" for the logarithm) –  J. M. Sep 14 '12 at 5:18
    
1  
@SjoerdC.deVries Will this eventually be deleted? If deleted, what happens to the nice answers here? Is it possible to merge the duplicates. –  Noble P. Abraham Sep 16 '12 at 15:52
add comment

3 Answers 3

up vote 8 down vote accepted
Plot[{Re[x^x], Im[x^x]}, {x, -1, 2}]
share|improve this answer
add comment

Here's a view that shows how the graph starts to spiral for negative $x$ values, if we take the complex values into account.

ParametricPlot3D[{x, Re[Exp[x*Log[x]]], Im[Exp[x*Log[x]]]}, 
  {x, -4, 2}, PlotRange -> All, ViewVertical -> {0, 1, 0},
  BoxRatios -> {2, 1, 1}, ViewPoint -> {2, 2, 12}]

enter image description here

In fact, if we write $x^x = e^{x\log(x)}$, this naturally generallizes to $x^x = e^{x\log(x) + 2i\pi k}$; each $2i\pi k$ represents another branch of the complex logarithm. In this context, we see that this graph just forms one spiral of a family of spirals.

x2x[0.0, _] = x2x[0, _] = 1;
x2x[x_, k_] := Exp[x (Log[x] + 2 I Pi k)];
Table[points3D[k] = Table[
  z =  x2x[x, k];
  {x, Re[z], Im[z]},
  {x, -4, 2, 0.005}],
{k, -7, 7}];
Graphics3D[Table[{If[k == 0, Thick, Opacity[0.5]], 
  Line[points3D[k]]}, {k, -4, 4}],    
  Axes -> True, PlotRange -> {{-4, 2}, {-4, 4}, {-4, 4}}, 
  BoxRatios -> {2, 1, 1}, ViewPoint -> {2, 2, 12}, 
  ViewVertical -> {0, 1, 0}]

enter image description here

In elementary classes, you might see the claim that $(p/q)^{p/q}$ is defined for $p$ negative and $q$ odd and positive. Thus the graph might look something like so.

Plot[x^x, {x, 0, 2}, PlotStyle -> Directive[Thick, Black],
  Epilog -> Point[Table[{i/31, Abs[(i/31)^(i/31)]}, {i, -63, -1, 2}]],
  PlotRange -> {{-2, 2}, {-2, 4}}]

enter image description here

From the complex perspective, the dots arise as spots where one of the spiral threads punctures the $x$-$z$ plane.

share|improve this answer
    
I chose yulinlinyu's as the answer because it answered my question directly and succinctly - but Mark Mcclure's answer goes above and beyond - and is the real jewel in this thread! –  Faisal Vali Sep 17 '12 at 18:17
add comment

As yulinyu has pointed out, something like the following will give you the desired plot.

Plot[Through[{Re, Im}[x^x]], {x, -2, 2}, Evaluated -> True]

You might also be interested in this excellent answer by Simon Woods to create a graph of the plot over the complex domain. Using his function and evaluating the following gives you a pretty picture

domainPlot[#^# &]

enter image description here

share|improve this answer
3  
For a second I thought I smoked .... but no –  belisarius Sep 14 '12 at 5:20
2  
Are you training your hypno-powers? –  belisarius Sep 14 '12 at 5:40
add comment

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