2
$\begingroup$

I tried Wolfram Mathematica, but could not pinpoint an answer. I tried to plot the function: f: x-> Floor[Sin[x]], but the graph is not even making room in the axis for the only dots of values equal to "1".

These points are only those of x's values equal to any positive integer multiple of Pi/2, where Floor[1] is 1. The plot command I used is this, just as it should be:

Plot[(Floor@*Sin)[x], {x, -Pi, Pi}]

enter image description here

Around x=Pi/2 there were no accurate plotting of the case x=Pi/2. When I adjusted the command to:
Plot[(Floor@*Sin)[x], {x, (Pi - 0.000001)/2, (Pi + 0.000001)/2}] Then the plot did jump to to the case f(x)=f(Pi/2)=1 as it should:

enter image description here

Is there a way to make the plot jump accordingly in other similar cases? After all this was a significant jump of one unit.

Options like PlotRange->All, Exclusions->None or ExclusionsStyle->Red did not bring the missing dot back.

$\endgroup$

2 Answers 2

2
$\begingroup$

As mentioned, this is due to sampling. I've had this problem before Plot, sampling, and why it does not display for some ranges

Another option might be to consider DiscretePlot?

f[n_] := (Floor@*Sin)[n*Pi/20]
DiscretePlot[f[n], {n, -20, 20}]

Mathematica graphics

If you do not want to see the vertical lines

 DiscretePlot[f[n], {n, -20, 20}, Filling -> None]

Mathematica graphics

$\endgroup$
1
$\begingroup$

You can use the undocumented form PlotPoints -> {n, {pt1, pt2, ...}} to force sampling at {pt1, pt2, ...}:

 Plot[(Floor@*Sin)[x], {x, -Pi, Pi}, 
   Exclusions -> None, 
   PlotPoints -> {100, {Pi/2}}, 
   Frame -> True, Axes -> False]

enter image description here

Note: on this undocumented form of PlotPoints see this answer by Ulrich Neumann.

$\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.