3
$\begingroup$

I was in doubt if this question should be asked in Mathematics.SE or Mathematica.SE, but I've decided this site would be more appropriate, because I think those who read my question here will know about both mathematics and Mathematica.

I tried to plot $n(-1)^n$ with Plot, but it showed nothing. When I tried to plot it with DiscretePlot, it worked. Why did that happen?

$\endgroup$
4
  • 2
    $\begingroup$ $n (-1)^n$ is real only for integer $n$ and complex for everything else. Plot[] skips complex values, so... $\endgroup$ Apr 17, 2013 at 0:41
  • 1
    $\begingroup$ Use this instead Plot[Re[x Exp[i x \[Pi] ]], {x, -1, 1}] $\endgroup$
    – Spawn1701D
    Apr 17, 2013 at 0:42
  • $\begingroup$ ...or Plot[n (-1)^Floor[n], {n, -5, 5}]. $\endgroup$ Apr 17, 2013 at 0:45
  • $\begingroup$ Actually $(-1)^n$ becomes a multivariable function. It may take a real value apart from when $n$ is integer (but of course not when $n$ is irrational). $\endgroup$
    – Spawn1701D
    Apr 17, 2013 at 0:49

3 Answers 3

11
$\begingroup$

Take what you need:

Plot[
  {Re, Im, Arg, Abs}[n (-1)^n] // Through,
  {n, 1, 10},
  Evaluated -> True
]

enter image description here

$\endgroup$
1
  • 4
    $\begingroup$ I can't help but to read Mr. Wizards posts in Professor Hubert J. Farnsworth's voice. $\endgroup$
    – jmlopez
    Apr 17, 2013 at 3:01
1
$\begingroup$

Perhaps @Gustavo Bandeira intended just discrete values of n. Then:

ListPlot[Table[n (-1)^n, {n, 1, 20}], PlotStyle -> PointSize[Large]]
$\endgroup$
1
  • 2
    $\begingroup$ OP did say that he has used DiscretePlot[]. $\endgroup$ Apr 17, 2013 at 3:31
1
$\begingroup$

See the mage of Araby
Get your functions, old and new
With a two-year guarantee
And a choice of colors, too

Map[Function[f, Plot[n (-1)^f[n], {n, -10, 10}, PlotLabel -> (n (-1)^f[n])]],
    {{Floor, Ceiling}, {Round, IntegerPart}}, {2}] // GraphicsGrid

Come on, pick one, sweetheart!

$\endgroup$
6
  • $\begingroup$ And what about the point $\frac{2}{3}$ for example? It is a real function there and to many other like this points. $\endgroup$
    – Spawn1701D
    Apr 17, 2013 at 9:31
  • $\begingroup$ @Spawn, Ah, for that you don't want the principal value of Power[]. I understand that Mathematica these days has the Surd[] function; that would be useful in the situation you think of. $\endgroup$ Apr 17, 2013 at 9:32
  • $\begingroup$ Actually 1 is the principal value for the odd roots the rest are complex of course. $\endgroup$
    – Spawn1701D
    Apr 17, 2013 at 9:36
  • $\begingroup$ @Spawn, I don't quite think so. To take $(-1)^{2/3}$ as an example, the real value is not the principal value, at least if we want our power function to have a branch cut that agrees with our branch cut choice for the logarithm. $\endgroup$ Apr 17, 2013 at 9:45
  • $\begingroup$ Just run it on wolfram alpha it will show you that 1 is the principal value. I suppose is a different definition for different purposes. $\endgroup$
    – Spawn1701D
    Apr 17, 2013 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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