Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there any way to mark integer points after plotting region in Mathematica? For example, if I:

RegionPlot[x >= 4 y && x <= 4 y + 3 , {x, 0, 63}, {y, 0, 15}]

Mathematica graphics

then it highlights the region but I want to see Y value corresponding to integer X value. Can I do it with Mathematica?

share|improve this question
    
I added a graphic to your post to help illustrate. Could you describe in more detail what you expect to see, please? –  Mr.Wizard Dec 11 '12 at 16:39
    
Like in above image I want to mark (x,y) where both x and y are integers. –  username_4567 Dec 11 '12 at 16:44
1  
You might want to wait a bit with the accept, as others may provide better answers. –  István Zachar Dec 11 '12 at 17:00
    
Yes I can do that .. –  username_4567 Dec 11 '12 at 17:01

4 Answers 4

Use the inequality to sow all integer coordinates that are inside the boundary of the region when iterating through all integer pairs of the full range:

pts = First@Last@Reap@Do[If[x >= 4 y && x <= 4 y + 3, Sow@{x, y}], {x, 0, 63}, {y, 0, 15}]
RegionPlot[x >= 4 y && x <= 4 y + 3, {x, 0, 63}, {y, 0, 15}, Epilog -> {Red, Point@pts}]

Mathematica graphics

share|improve this answer
    
Amazing..Thanks a lot.. –  username_4567 Dec 11 '12 at 16:58

Another way to generate all the points is by using Reduce:

points = {x, y} /. 
 List@ToRules@
   Reduce[x >= 4 y && x <= 4 y + 3 && 0 < x < 63 && 0 < y < 15, {x, y}, Integers]

If you give bounds (and thus constrain the possible solutions to a finite set), Reduce will typically list all solutions.

Then just plot them with Point or ListPlot:

ListPlot[points]

Show them together with the RegionPlot:

Show[ListPlot[points], RegionPlot[...]]

Thanks to Mr.Wizard to pointing me to the following relevant note in the documentation:

Mathematica enumerates the solutions explicitly only if the number of integer solutions of the system does not exceed the maximum of the $p^{\text{th}}$ power of the value of the system option DiscreteSolutionBound, where $p$ is the dimension of the solution lattice of the equations, and the second element of the value of the system option ExhaustiveSearchMaxPoints.

share|improve this answer
2  
Might want to mention ExhaustiveSearchMaxPoints. +1 –  Mr.Wizard Dec 11 '12 at 18:29
    
@Mr.Wizard Thanks for the pointer. I didn't know about this option. –  Szabolcs Dec 11 '12 at 23:42
    
I changed your documentation link to an anchor I thought was more appropriate. If you disagree change it back, or perhaps add a second one. –  Mr.Wizard Dec 12 '12 at 19:30
    
@Mr.Wizard I agree, but I am usually too lazy to dig out the precise anchor (if it is not linked to and I can't just copy the link). Is there an easier way than using the dev tools of the browser or looking at the web page source? –  Szabolcs Dec 13 '12 at 0:23
    
There's a Meta post about that. I still use View Selection Source myself; it really doesn't take long. If your browser only lets you view the source of the entire page I can see the problem. –  Mr.Wizard Dec 13 '12 at 1:36

Alternatively you can generate just the points you want and then plot them :

data = DeleteCases[Flatten[Outer[Boole[4 #2 <= #1 <= 4 #2 + 3] {#1, #2} &, 
    Range[0, 63], Range[0, 15]], 1], {0, 0}];

Show[RegionPlot[x >= 4 y && x <= 4 y + 3, {x, 0, 63}, {y, 0, 15}],  ListPlot[data]]

plot

share|improve this answer

Another, using smart and fast functions like Array and Tuples, thus a bit more recommended way :

RegionPlot[ x >= 4 y && x <= 4 y + 3, {x, 0, 63}, {y, 0, 15}, Epilog -> { 
            Red, PointSize[0.005], 
            Point[ Join @@ Tuples /@ Array[ {Range[4 #, 4 # + 3], {#}} &, {16}, 0]]}, 
            AspectRatio -> 15/63 ]

enter image description here

share|improve this answer
    
By the way, you can just do AspectRatio -> Automatic... –  Rahul Dec 12 '12 at 2:30
    
@RahulNarain That's all ? –  Artes Dec 12 '12 at 19:04
    
I mean, instead of manually specifying 15/63. –  Rahul Dec 12 '12 at 21:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.