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.
problem with syntax of the equation Topic is solved
Re: problem with syntax of the equation
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
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
-
- User
- Posts: 38
- Joined: 4 years ago
-
- User
- Posts: 3
- Joined: 4 years ago
Re: problem with syntax of the equation
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
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
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.
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.
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
-
- User
- Posts: 3
- Joined: 4 years ago
Re: problem with syntax of the equation
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...
-
- User
- Posts: 3
- Joined: 4 years ago
Re: problem with syntax of the equation
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
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.
If, for whatever reason, you want to have a column vector you can do this as follows:
Cheers
Renger
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;
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
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
-
- User
- Posts: 38
- Joined: 4 years ago
Re: problem with syntax of the equation
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
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
Last edited by Alexanre.ito 4 years ago, edited 2 times in total.
Re: problem with syntax of the equation
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
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
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist