Message Boards Message Boards

0
|
3556 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:
GROUPS:

Plot and Discrete Plot give vastly different results

Posted 9 years ago

If you can access Wolfram Cloud, this sheet shows it:

Plot and DiscretePlot Comparison

I am plotting Mod[x! , 2^x]

Basically, DiscretePlot shows the correct values, but Plot goes to 0 for values > 23

Why does Plot fail? I guess the way it is calculating factorial has something to do with it.

POSTED BY: Stefan Karos
4 Replies
Posted 9 years ago

thank you. this gets me closer

Plot[Mod[x!, 2^x], {x, 20, 35}, PlotPoints -> 10, WorkingPrecision -> 40]

but I'd like to rescale the y -axis so I can see all the numbers (or possibly a logarithmic scale?)

and is it possible to print out the values when they are <100? ( so I can see the value of x as well as the result when it is close 0)

POSTED BY: Stefan Karos

I now see your screenshot;

The fix is to add a working-precision option:

Plot[Mod[x!, 2^x], {x, 0, 30}, PlotPoints -> 100, WorkingPrecision -> 30]

The reason is quite easy: DiscretePlot uses integer arithmetic and will automatically switch to a type of number that can have many many digits. While for Plot it uses MachinePrecision (Real) numbers by default, and because you are working with very big numbers this gets problematic. Therefore by providing a WorkingPrecision that is high it will switch to 'arbitrary precision' numbers which can handle the huge numbers you are using.

POSTED BY: Sander Huisman
Posted 9 years ago

DiscretePlot[Mod[n !,2^n],{n,20,35}] discrete plot

Plot[Mod[m !, 2^m], {m,20,35}] plot

POSTED BY: Stefan Karos

What do you mean with 'fail' ? x! grows as x^x, so much slower than 2^x, so the 'mod' will chop up the function many many times and it will look like a lot of vertical lines... The values DiscretePlot shown (the integer ones) might not appear exactly in the Plot version, as it samples PlotPoints number of samples which might not be exactly integers...

Edit: Unfortunately we can not see the notebook as we don't have permission to do so. Therefore I'm speculating. Can you provide a screenshot?

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract