Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.6K Views
|
3 Replies
|
1 Total Like
View groups...
Share
Share this post:

Getting the mixed integer feasible points from a region

Posted 5 years ago

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.

POSTED BY: Miranda Li
3 Replies
Posted 5 years ago

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]

enter image description here

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

POSTED BY: Rohit Namjoshi
Posted 5 years ago

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.

POSTED BY: Rohit Namjoshi
Posted 5 years ago

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!

POSTED BY: Miranda Li
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard