Page 1 of 2

problem with syntax of the equation

Posted: Tue Aug 13, 2019 3:16 am
by Alexanre.ito
I'm new with optimization and GAMS. I not sure how to declare the Manning equation. This equation describe the flow dynamic on free flow condition, considering geometry and viscosity.

I declared scalar and variables as:
man manning coef / 1.30e-2 /
q(n,n) flow (m**3 per s)
ir(n,n) inclination (m per m)
am(n,n) area (m**2)
pm(n,n) perimeter (m)

and the equation like
mann.. man*q(n,n)/sqrt(ir(n,n) =e= (am(n,n)**(5/3)/(pm(n,n)**(2/3))

but i'm not shure if is the correct form

the variable that I need to find is "ir".
But "am" and "pm" may vary depending on the "ir" variable as well, because of another energy equation and other free surface flux conditions.

My question is, the form that I declared the equation (mann) is correct or I need to isolate the variable "ir" that I need to find? to have convergency or have a faster model.

Re: problem with syntax of the equation

Posted: Tue Aug 13, 2019 3:22 pm
by Renger
Looks fine, and as long as you have at least as many equations as variables in your model, there is nothing wrong with using an implicit definition of this variable.
Cheers
Renger

Re: problem with syntax of the equation

Posted: Tue Aug 13, 2019 7:45 pm
by Alexanre.ito
Renger wrote: 4 years ago Looks fine, and as long as you have at least as many equations as variables in your model, there is nothing wrong with using an implicit definition of this variable.
Cheers
Renger
Thanks a lot.

Re: problem with syntax of the equation

Posted: Wed Aug 14, 2019 2:28 pm
by aruni176102002
I am new to GAMS...I have interfaced matlab and gams....however while solving it, I am getting the error 149 and 148....Can someone help....Parameters f, b_L...etc are column vectors whereas Cmat and H are matrices....Can anyone help me?


Set j /1*23/;
Set i /1*75/;
Set k/ 1*23/;
Set l/1*75/;
Set m/1*75/;
Set n /1*23/;
Set p /1*23/;
Set q /1*23/;
Set r /1*23/;




Parameter Cmat(i,j);
Parameter f(k);
Parameter H(n,n);
Parameter b_L(l)
Parameter b_U(m)
Parameter x_L(p)
Parameter x_U(q);

$GDXIN 'MtoG1'
$LOADIDX Cmat f H b_L b_U x_L x_U
$GDXIN

Free Variables var, func;
Equations
obj
con1
con2;
obj .. func =e= 0.5 * var^T * H(n,n) * var + f(k)^T * var;

con1 .. x_L(p) =l= var =l= x_U(q);

con2 .. b_L(l) =l= Cmat(i,j) * var =l= b_U(m);
Model project1 / all / ;
Solve project1 using NLP minimizing func;
*Parameter xval;
*xval=x.l;
*Execute_UnloadIdx 'GtoM1' xval;
*display x.l

Re: problem with syntax of the equation

Posted: Wed Aug 14, 2019 5:38 pm
by Renger
Hi

You could search in this forum: It will give you 16 pages with posts with the same answer... (and read the guidelines).

Cheers

Renger

PS. If you enter code in your post, use the code block (the symbol in the menu bar of the editor with the </> sign on it. This keeps the code nicely formatted and readable.

Re: problem with syntax of the equation

Posted: Thu Aug 15, 2019 12:27 pm
by aruni176102002
I just want to know whether the matrices from matlab workspace is loaded in the same way as they are....If the matrix is a column vector, which is considered as one dimensional variable, how can I write the transpose of that variable ? Please help me...

Re: problem with syntax of the equation

Posted: Thu Aug 15, 2019 12:49 pm
by aruni176102002
I have loaded the matrices from matlab. Now some of the matrices are column vectors and the elements are mostly zeros. I want to know whether they are loaded as column vectors in gams. How to write transpose of a variable. If my variable is x1 with j rows and 1 column, how can I write the transpose of x1....Will it be x1(j)^T?

Re: problem with syntax of the equation

Posted: Thu Aug 15, 2019 1:44 pm
by Renger
Hi
Why do you want to have a transposed vector. Multiplying a vector with a matrix can be done in Gams without the use of transposing.

Code: Select all

set i /i1*i4/;
set j /j1*j5/;
parameter x(i), m(i,j);
x(i) = uniform(0,1);
m(i,j) = uniform(0,1);
display x, m;

* Multiplying m with x:

parameter leftm(j);

leftm(j) = sum(i, x(i) * m(i,j));

display leftm;

* transposing M

parameter mt;
mt(j,i) = m(i,j);

display mt;

parameter rightm(j);

rightm(j) = sum(i, x(i) * mt(j,i));

display rightm;
If, for whatever reason, you want to have a column vector you can do this as follows:

Code: Select all

parameter xc(i,*);

xc(i,"Mytransposed") = x(i);
display xc;

    mytranspo~

i1       0.172
i2       0.843
i3       0.550
i4       0.301
    mytranspo~

i1       0.172
i2       0.843
i3       0.550
i4       0.301


Cheers
Renger

Re: problem with syntax of the equation

Posted: Thu Aug 22, 2019 8:41 pm
by Alexanre.ito
I'd like to know
if GAMS undestand this situation
...
n nodes / n1 * n48 /
a(n,n) /..../;
....
alias(n,np,i,j);
...
q(n) - scalar
q(a) - variable
...
eq1(a(i,j)).. q(a(n,np)) =e= sum(q(a(n,np)$(np=i)) + q(n)

GAMS understand :
eq(i)
eq(i,j)


but GAMS undestand:
eq(a(i,j)) ???

my objective is to elaborate an equation that the flow of some arc considering the sum of all arcs that end at the beginning node of the arc that I want to analyse

Re: problem with syntax of the equation

Posted: Fri Aug 23, 2019 8:36 am
by Renger
Hi

It is not clear what you want to do with this equation. My advice: write it down as a proper mathematical expression, read how to use the sum in GAMS as well as the $-sign, and proceed from there.

Cheers

Renger