1
$\begingroup$

I have the following problem to solve in Mathematica, but (maybe because of my inexperience) it seems quite a really one to code properly.

Given a line $y=mx+q$ with $q>0$ and $m<0$, this intersects the positive $x$-axis and a positive $y$-axis to form a rectangular triangle in the first quadrant.

I would like to find an algorithm that will allow me to write all the integral points $(x,y)$ contained inside of such triangle (or on in boundary) in function of $m$ and $q$. With integral points I mean points such that $x$ and $y$ are integer numbers. Furthermore (an this is crucial) I would like to have the set of coordinates of such output points as entries of a list.

So far I can solve the problem via a nested "while cycle" but the output is not a list, rather it is many cells, each one printing the coordinates of one point inside.

Any suggestions?

$\endgroup$
4
  • 6
    $\begingroup$ Like this: {x, y} /. {ToRules[Reduce[y < 11 - 7 x && x > 0 && y > 0, {x, y}, Integers]]}? $\endgroup$ Feb 1, 2017 at 1:34
  • $\begingroup$ Run J. M.'s code and then (for fun): Graphics[Point /@ %] $\endgroup$ Feb 1, 2017 at 1:54
  • 1
    $\begingroup$ Closely related question: mathematica.stackexchange.com/q/135141/3066 $\endgroup$
    – m_goldberg
    Feb 1, 2017 at 4:45
  • $\begingroup$ this one is about trivial to do directly as well Flatten[Table[ {x, y}, {x, 0, -q/m} , {y, 0, m x + q }], 1] $\endgroup$
    – george2079
    Feb 1, 2017 at 21:50

0

Browse other questions tagged or ask your own question.