Defining a parameter range

249 views
Skip to first unread message

Abdulrahman Aldeek

unread,
Dec 17, 2020, 8:40:01 AM12/17/20
to AMPL Modeling Language
Dears

I'm trying to write the following constraint

subject to constraint_5 :
tan(g)>=y;

where g is in the range 0<=g<=30. I want to make sure that tan(g) for any given point in this range will be bigger than the variable y. How should I define g to achieve that?

Regards

AMPL Google Group

unread,
Dec 18, 2020, 12:02:48 PM12/18/20
to AMPL Modeling Language
Is g a variable that is used in other objective and/or constraint expressions? Then you could write

var y;
var g >= 0, <= 30;
subject to constraint_5: tan(g) >= y;


But if by "30" you mean "30 degrees" then you need to convert the argument of g to radians, for example by defining y and g as above and then writing

param pi = 4*atan(1);
subject to constraint_5: tan(g*(pi/180)) >= y;



--
Robert Fourer
am...@googlegroups.com
{#HS:1371693594-96567#}

Abdulrahman Aldeek

unread,
Dec 18, 2020, 5:05:42 PM12/18/20
to AMPL Modeling Language
g is not a variable. I want to define a constraint where (tan(g)>=y) for all g in the range 0<g<30 degrees. I'm aware of the radian issue. What is the easiest way to do that?

AMPL Google Group

unread,
Dec 20, 2020, 6:29:34 PM12/20/20
to AMPL Modeling Language
You could think of writing

subject to constraint_5 {g in interval(0,30)}: tan(g*(pi/180)) >= y;

But this would define an infinite number of constraints, and so AMPL rejects it, with the error message "Attempt to iterate over an interval". Instead you could try to define one constraint like this:

subject to constraint_5: forall {g in interval(0,30)} tan(g*(pi/180)) >= y;

But AMPL rejects this with the same error message. Basically, AMPL will reject any statement that contains indexing, explicit or implicit, over a continuous interval.

(In this particular case you could reason that since tan(0) = 0 and the tan function is increasing from 0 to 30, the constraint is equivalent to 0 >= y.)


--
Robert Fourer
am...@googlegroups.com
{#HS:1371693594-96567#}
On Fri, Dec 18, 2020 at 10:05 PM UTC, AMPL Modeling Language <am...@googlegroups.com> wrote:
g is not a variable. I want to define a constraint where (tan(g)>=y) for all g in the range 0<g<30 degrees. I'm aware of the radian issue. What is the easiest way to do that?

On Fri, Dec 18, 2020 at 5:02 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
Is g a variable that is used in other objective and/or constraint expressions? Then you could write

var y;
var g >= 0, <= 30;
subject to constraint_5: tan(g) >= y;


But if by "30" you mean "30 degrees" then you need to convert the argument of g to radians, for example by defining y and g as above and then writing

param pi = 4*atan(1);
subject to constraint_5: tan(g*(pi/180)) >= y;



--
Robert Fourer
am...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages