Hello, I am trying to get all feasible points from the region plotted by (x - 1.1)^2 <= y, x is integer, y is continuous variable. The following is the code that I implemented:
pts = First@Last@Reap@Do[If[(x - 1.1)^2 <= y, Sow@{x, y}], {x, 1, 3}, {y, 0, 25}]
However, this code gives my points with both x and y are integers. Is there any way to make x be integer and y be real when I get all feasible points? I want to plot the convex hull of this mixed integer feasible region.
Thank you.
Hi Miranda,
Specify a non-integer step size for y. e.g.
points = Table[If[(x - 1.1)^2 <= y, {x, y}, Nothing], {x, 1, 3}, {y, 0, 25, .1}] //
Flatten[#, 1] &;
ListPlot[points]
The inequality can also be solved to get an exact solution for the range of y. e.g.
Reduce[(x - 11/10)^2 <= y && (x == 1 || x == 2 || x == 3) && y <= 25, y]
(* (x == 1 && 1/100 <= y <= 25) || (x == 2 && 81/100 <= y <= 25) || (x == 3 && 361/100 <= y <= 25) *)
Not sure what you mean by
I want to plot the convex hull of this mixed integer feasible region
Hello Rohit,
Thank you for your help. However, when I tried the Reduce function in my Mathematica, I got the error Reduce::ivar: 4 is not a valid variable, and output: Reduce[True, 4]. I also tried many other examples with Reduce function but got the same error. Do you know the reason I got such an error and how to fix it? Thank you so much!
Hi Miranda,
Please post the code which generated the error. Perhaps you have a value previously assigned to one of the symbols in your equations.