## trigonometric functions

Archiver
User Posts: 7876
Joined: 4 years ago

### trigonometric functions

Hi friends, I have some problems in programming some equations in gams, I am new using gams and I donâ€™t have very clear how to program equation with trigonometric functions.

One of the equations that I am having problems with is this:

P=âˆ‘ Vi*Vj*(Gij*cos(Oi-Oj)+Bij*sin(Oi-Oj))

j=1

The tutorial says that gams Currently have no support for other functions, including the trigonometric functions cos(x),sin(x), etc.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.

Archiver
User Posts: 7876
Joined: 4 years ago

### Re: trigonometric functions

GAMS does support the math functions you have identified. Go to the McCarl's guide and search on functions and select Other Mathematical functions and you will see a broad list of supported math functions. You can calculate these values using gams outside of an optimization model, however if you are using the equation inside the optimization you will need a non linear solver.

When we have problems of these types we usually calculate these equations in the pre-model for all possible combinations and then write an optimization to select the values that either minimize or maximize the objective function. Then you can use a traditional solver which is always a lot faster than a non linear solver approach.

Regards,
John

On Tue, Jan 6, 2015 at 11:33 AM, asier bernardo mugarra flores wrote:

Hi friends, I have some problems in programming some equations in gams, I am new using gams and I donâ€™t have very clear how to program equation with trigonometric functions.

One of the equations that I am having problems with is this:

P=âˆ‘ Vi*Vj*(Gij*cos(Oi-Oj)+Bij*sin(Oi-Oj))

j=1

The tutorial says that gams Currently have no support for other functions, including the trigonometric functions cos(x),sin(x), etc.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.

Archiver
User Posts: 7876
Joined: 4 years ago

### Re: trigonometric functions

For Power Flow Equation best internet resource for GAMS is

https://www.princeton.edu/~rvdb/ampl/nl ... index.html

best regards

Abraham

On Tue, Jan 6, 2015 at 9:33 PM, asier bernardo mugarra flores wrote:

Hi friends, I have some problems in programming some equations in gams, I am new using gams and I donâ€™t have very clear how to program equation with trigonometric functions.

One of the equations that I am having problems with is this:

P=âˆ‘ Vi*Vj*(Gij*cos(Oi-Oj)+Bij*sin(Oi-Oj))

j=1

The tutorial says that gams Currently have no support for other functions, including the trigonometric functions cos(x),sin(x), etc.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.

Alexanre.ito
User Posts: 23
Joined: 1 year ago

### Re: trigonometric functions

Hi, I was studding in how to implement trigonometric functions.

I founded this site, about Extrinsic Functions.
https://www.gams.com/latest/docs/UG_Ext ... aryExample

I need to use the angle with radian unit. So at GAMS website they suggest to use Function Libraries, an example, trilib01.gms , trilib02.gms and trilib03.gms .
https://www.gams.com/latest/testlib_ml/ ... lib01.html C
https://www.gams.com/latest/testlib_ml/ ... lib02.html Delphi
https://www.gams.com/latest/testlib_ml/ ... lib03.html Fortran

But how I suppose to use this examples in my mproblem.

Is just save in my folder, or a specific folder?

What the difference of using:

Code: Select all

``Function <InternalFuncName> /<InternalLibName>.<FuncName>/;``
or

Code: Select all

``````\$ifThen set nocomp
*  Use precompiled library provided by testlib
\$  batinclude precomp.inc tricclib
\$else
*  Compile library from source code
\$  batinclude compilec.inc tri
\$endIf

function myCos        / myLib.Cosine /
mySin        / myLib.Sine   /
myPi         / myLib.Pi     /;``````
??

Tnks

Manassaldi
User Posts: 93
Joined: 3 years ago
Location: Rosario - Argentina

### Re: trigonometric functions

GAMS supports trigonometric functions.
What are the functions you have problems with?
Extrinsic functions are to implements your own functions.

Best

Alexanre.ito
User Posts: 23
Joined: 1 year ago

### Re: trigonometric functions

Manassaldi wrote:
7 months ago
GAMS supports trigonometric functions.
What are the functions you have problems with?
Extrinsic functions are to implements your own functions.

Best

My problems is with this equation:

Code: Select all

``````* Diameter for each tube with flow
dred(a)..   dr(a)    =e= vcPower((abc1(a)*man*qr(a)/sqrt(ir(a))),(3/8));
eq1(a)..    abc1(a) =e= vcPower(3.0844*theta(a),(1/4))/abc2(a);
eq2(a)..    abc2(a) =e= vcPower((theta(a) - sin(theta(a))),(5/8));``````
That return a Error:
Error at line ....: division by zero (0)

than I tried to insert a condition "\$(theta(a) gt 0)":

Code: Select all

``````* Diameter for each tube with flow
dred(a)..   dr(a)                            =e= vcPower((abc1(a)*man*qr(a)/sqrt(ir(a))),(3/8));
eq1(a)..    abc1(a)\$(theta(a) gt 0)  =e= vcPower(3.0844*theta(a),(1/4))/abc2(a);
eq2(a)..    abc2(a)\$(theta(a) gt 0)  =e= vcPower((theta(a) - sin(theta(a))),(5/8));``````
this code not work even of I used "\$(qn(a) gt 0)" to indicate if the tube have flow or not.

a error appear:
Endogenous \$ operation not allowed

I'm using :

Code: Select all

``Solve network using MINLP minimizing cost``
Best

Manassaldi
User Posts: 93
Joined: 3 years ago
Location: Rosario - Argentina

### Re: trigonometric functions

That is not a GAMS valid sentence. Maybe you are confused in the way "GAMS" works. I think i can't help you
Best

Renger
Posts: 588
Joined: 4 years ago

### Re: trigonometric functions

Hi
This might be resolved by setting a starting value that is not equal to zero. If you don't set a starting value for your variables, Gams assumes zero.
You could for example set THETA.L = 1;
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

Alexanre.ito
User Posts: 23
Joined: 1 year ago

### Re: trigonometric functions

Renger wrote:
6 months ago
Hi
This might be resolved by setting a starting value that is not equal to zero. If you don't set a starting value for your variables, Gams assumes zero.
You could for example set THETA.L = 1;
Cheers
Renger
Yes! this help with this problems.
Thanks