7
$\begingroup$

I have solved with Mathematica 9 the following integer inequalities using Reduce:

eq = Reduce[
  m (k - 1) + (k - 2) == c k && m >= 2 && k >= 2 && c >= 1, {k, m, 
   c}, Integers, Backsubstitution -> True]

(* (k | m | c) \[Element] Integers && k >= 2 && m >= 2 && 
 c == (-2 + k - m + k m)/k *)

better = Reduce[
  m (k - 1) + (k - 2) <  c k && m >= 2 &&  k >= 2 && c >= 1, {k, m, 
   c}, Integers, Backsubstitution -> True]

(* (c \[Element] Integers && k == 2 && m == 2 && 
   c >= 2) || ((m | c) \[Element] Integers && k == 2 && m >= 3 && 
   c > m/2) || ((k | m | c) \[Element] Integers && k >= 3 && m >= 2 &&
    c > (-2 + k - m + k m)/k) *)

worst = Reduce[
  m (k - 1) + (k - 2) >  c k && m >= 2 &&  k >= 2 && c >= 1 , {k, m, 
   c}, Integers, Backsubstitution -> True]

(* ((m | c) \[Element] Integers && k == 2 && m >= 3 && 
   1 <= c < m/2) || ((k | m | c) \[Element] Integers && k >= 3 && 
   m >= 2 && 1 <= c < (-2 + k - m + k m)/k) *)

Now I need to plot them. However, using RegionPlot3D I can only plot a region made of reals, while the solutions are integers. What is the proper way to plot the solutions when the domain is Integers ?

$\endgroup$
7
$\begingroup$

Update: you can use your conditions to define the RegionFunction in ListPointPlot3D without having to use Reduce. For example, for the set better:

 ListPointPlot3D[Tuples[Range[20], 3], ImageSize -> 500,BoxRatios -> 1,
  RegionFunction -> Function[{m, k, c}, 
   m (k - 1) + (k - 2) < c k && m >= 2 && k >= 2 && c >= 1] ]

enter image description here


You can use Graphics3D or ListPointPlot3D using all the integer solutions that lie in the plot range of your choice:

dom =0 <= k <= 20 && 0 <= m <= 20 && 0 <= c <= 20; (* this plays the role of PlotRange *)
eq = Last /@ # & /@ {ToRules[
 Reduce[m (k - 1) + (k - 2) == c k && m >= 2 && k >= 2 && c >= 1 && dom,
    {k, m, c}, Integers, Backsubstitution -> True]]};
better = Last /@ # & /@ {ToRules[
  Reduce[m (k - 1) + (k - 2) < c k && m >= 2 && k >= 2 && c >= 1 && dom, 
    {k, m, c}, Integers, Backsubstitution -> True]]};
worse = Last /@ # & /@ {ToRules[
  Reduce[m (k - 1) + (k - 2) > c k && m >= 2 && k >= 2 && c >= 1 && dom,
    {k, m, c}, Integers, Backsubstitution -> True]]};
Graphics3D[{PointSize[.02], Opacity[.3], Blue, Point@better, Green, 
   Point@worse, Opacity[1], Red, Point@eq}] 

enter image description here

ListPointPlot3D[{eq, better, worse}, 
  PlotStyle -> {Directive[PointSize[.02], Red], Blue, Green}, BoxRatios -> 1]

enter image description here

$\endgroup$
  • $\begingroup$ Great answer. Thank you very much for spending your time answering; I learned a lot about visualization in Mathematica today. $\endgroup$ – Massimo Cafaro Mar 19 '13 at 11:58
  • $\begingroup$ @Massimo, my pleasure. $\endgroup$ – kglr Mar 19 '13 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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