## variable syntax problem

Problems with syntax of GAMS
s0r0n
User
Posts: 4
Joined: 2 weeks ago

### variable syntax problem

Hello,

I have 2 issues. Firstly I need to declare the square of a variable with 2 arguments, but sqr(V(i,t)) doesn't work.
As for the other, I have the following parameter: LPline_max(f,t,seg) and declared the variable LP_line(f,t,seg). However the following equation gives the errors 145 and 148 for both of them.

Code: Select all

``Net16ap2(f,t) .. LP_line(f,t,1) =l= LPline_max(f,t,1);``
.

bussieck
Moderator
Posts: 147
Joined: 2 years ago

### Re: variable syntax problem

1) When you say 'but sqr(V(i,t)) doesn't work' what does this mean. The syntax is correct. But perhaps there is a problem somewhere else.
2) In GAMS labels always need quoting. So if you want to access the element '1' from seg do it as follows:

Code: Select all

``Net16ap2(f,t) .. LP_line(f,t,'1') =l= LPline_max(f,t,'1');``
-Michael

s0r0n
User
Posts: 4
Joined: 2 weeks ago

### Re: variable syntax problem

Thank you for your response,second issue is solved. For the first one, I want to do something like this

Code: Select all

``````Set i /1*24/
t /1*24/;
Variables
sqr(V(i,t));``````
but 4 errors appear all the time.

bussieck
Moderator
Posts: 147
Joined: 2 years ago

### Re: variable syntax problem

That makes little sense. What should it mean to declare the sqr of a variable? You can use the sqr of a variable in an expression in an equation or in an assignment statement:

Code: Select all

``````Set i /1*24/
t /1*24/;
Variables V(i,t);
equation e;
e.. sum((i,t), sqr(V(i,t)) =l= 1;
``````
-Michael

s0r0n
User
Posts: 4
Joined: 2 weeks ago

### Re: variable syntax problem

I need to solve the problem as mip
Last edited by s0r0n on Tue Sep 11, 2018 10:32 am, edited 3 times in total.

bussieck
Moderator
Posts: 147
Joined: 2 years ago

### Re: variable syntax problem

MIP often means MILP which only allows linear expressions, so you can't use sqr of variables. I think you need to go back to the basics. Good luck.

-Michael

s0r0n
User
Posts: 4
Joined: 2 weeks ago

### Re: variable syntax problem

I get that, this picture might help you get my point,it wasn't uploaded at my previous post
Attachments

bussieck
Moderator
Posts: 147
Joined: 2 years ago

### Re: variable syntax problem

So if the variable only shows up squared in the model then it is a "naming" issue. Just call the variable Vsqr and after the solve you get the value of V by taking sqrt of Vsqr and decide about the sign.

-Michael