1
$\begingroup$

I use DiscretePlot for a function $f$ and the result is

enter image description here

As I see, the range of the function includes negative values. Then, when I use ScalingFunctions -> "Log", I obtain

enter image description here

Here, the negative range of the function is given by positive values. Is this true?

$\endgroup$
4
  • 1
    $\begingroup$ What version are you using? With v12.1.1, Clear["`*"]; DiscretePlot[10 (-1)^n, {n, 0, 10}, ScalingFunctions -> "Log"] correctly displays the result of 10 for only the even values of n since for odd values of n the Log is complex. Since your option is displayed in Red, it appears that it is not a valid option in your version. Was there some error message? $\endgroup$
    – Bob Hanlon
    Oct 23, 2020 at 17:03
  • $\begingroup$ @BobHanlon Thanks. No, there is not an error. Then, what other commands I can use to get a correct result? The version is 10.4. $\endgroup$
    – charmin
    Oct 23, 2020 at 17:22
  • $\begingroup$ People here generally like users to post code as Mathematica code instead of just images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find this meta Q&A helpful $\endgroup$
    – Michael E2
    Oct 24, 2020 at 1:04
  • 1
    $\begingroup$ The red highlighting usually indicates that the option is unknown for the function. (I don't have V10.4 to check.) $\endgroup$
    – Michael E2
    Oct 24, 2020 at 1:12

1 Answer 1

2
$\begingroup$

If I correctly understand it, you want to build a log-plot of a fuction taking negative values. In this case the ScalingFunctions -> "Log" option does not do the job. This can be done as follows. Compare

DiscretePlot[(-1)^n*n!, {n, 2, 7}, PlotRange -> All]

enter image description here

with

DiscretePlot[Piecewise[{{Log[Max[(-1)^n*n!, 0]], (-1)^n*n! >= 
 0}, {-Log[-Min[(-1)^n*n!, 0]], (-1)^n*n! < 0}}], {n, 2, 7}]

enter image description here

$\endgroup$

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.