0

When running the command:

Plot[1/x, {x, 0, 10}] 

I get very weird output:
enter image description here
Not only that, but when running

Plot[1/x, {x, 0, 1000}, Mesh -> All] 


Which should mark the points it generated the lines between, gives me this:
enter image description here
Please note that its 1000 here - not 10.
After reading Mathematica's explanation about Plot - it says that it generates more points if the function changes fast. The function 1/x is changing very slow - and I though that Mathematica isn't generation enough points - but using Mesh -> All I showed that it is incorrect.

Did anyone encounter this weird behavior? Can anyone please explain to me what causes this, and how can it be fixed?



P.S: This isn't the only function which gives bad output - its actually quite common.
P.P.S: I tried playing with MaxRecursion and WorkingPresicion - and it did not help.

Edit: I've just notices that the X axis isn't 0 - if you look at the first graph, you will see 0.4 as the last number, and 0.6 above it. The X axis is actually 0.2! So maybe the question is: why is the X axis at 0.2 and not 0?

3 Answers 3

4

I don't see any weirdness in your first plot, I see the graph of a hyperbola. Mathematica has even been kind enough to you to ignore your attempt to evaluate 1/0.

In your second plot, I think that you are expecting Mathematica to draw 1000 points along the line it plots ? How many pixels have you given it in which to draw those 1000 points in the x-direction ? I think that what you are seeing is an artefact common to most computer-based drawings: ask for 1000 points across (perhaps) 250 pixels and something's got to give. Or perhaps I don't understand why you are concerned about the output.

Finally, you ask: why is the X axis at 0.2 and not 0

The answer is that Mathematica has decided that the graph will look good that way. If you want to force the x-axis to cross the y-axis at 0, use the AxesOrigin option in your Plot command.

Sign up to request clarification or add additional context in comments.

1 Comment

At first I though that the X plane IS 0 - so it was very weird that the graph passed it.
3

Well, mma is just trying to be kind. If you enter Plot[1/x, {x, 0, 10}, PlotRange -> All, PlotStyle -> Thick] you will get the correct plot range, but since it's infinity (for the y axis), then the rest of the function is basically zero. So you would see an "empty" plot, which is even more non intuitive...

Comments

2

You may find value in DiscretePlot:

DiscretePlot[1/x, {x, 0.5, 10, 0.2}, PlotRange -> All, AxesOrigin -> {0, 0} ] 

Mathematica graphics

Or add option Joined -> True and get:

Mathematica graphics

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.