6
$\begingroup$

I have a simple function that I want to plot. I am using Mathematica 8 on a windows machine.

I type the following code:

Plot[100*0.5^n,{n,0,20}];

And the resulting graph only goes to 25 on the y not 100 like it should. Should I be telling Mathematica to do so?

$\endgroup$
2
  • 3
    $\begingroup$ have you looked at PlotRange in the documentation? $\endgroup$
    – rm -rf
    Jul 17, 2012 at 2:16
  • $\begingroup$ I have not, I will do so. Thank you! $\endgroup$ Jul 17, 2012 at 2:50

3 Answers 3

12
$\begingroup$

First the reason: Mathematica has to try to display the interesting part of the function for you. Since the function is on a long range very small, it assumes you maybe want a smaller range. Such an approach works most of the times very well but not always.

You have the chance to adjust the range of the plotting by using the PlotRange option:

Plot[100*0.5^n, {n, 0, 20}, PlotRange -> All]
$\endgroup$
1
  • $\begingroup$ Thank you much, I had an inkling that Mathematica was trying to show me what it thought I wanted, y I no let program tell me what's best? $\endgroup$ Jul 17, 2012 at 2:53
4
$\begingroup$

Like halirutan says you can use PlotRange -> All to see the full graph over the given input range. Note that yo can also use PlotRange to select part of the output range:

Plot[100*0.5^n, {n, 0, 20}, PlotRange -> {0, 10}]

If you use PlotRange with two ranges the first one is the range on your x-axis, and overrides the range you chose for the Plot:

Plot[100*0.5^n, {n, 0, 20}, PlotRange -> {{5, 10}, {0, 10}}]
$\endgroup$
2
  • $\begingroup$ That makes for an interesting use of PlotRange now I know specifically how to zoom in on parts of the Range that I might desire. $\endgroup$ Jul 17, 2012 at 13:50
  • $\begingroup$ @MCP_infiltrator - yes, that was the point of my answer. Enjoy :-) $\endgroup$
    – stevenvh
    Jul 17, 2012 at 13:58
2
$\begingroup$

Another possibility is to plot the Log of your function; this will show the interesting feature :

LogPlot[100*0.5^n, {n, 0, 20}]

LogPlot

$\endgroup$
1
  • $\begingroup$ This does indeed show an interesting feature, I did not even think to plot the log of it. $\endgroup$ Jul 17, 2012 at 13:51

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.