Solving Simultenous Equations

Hi,

I am new to GAMS and wants to solve two simultenous equations;
4X2Sin(X1) = -0.6
4SQR(X2)-4X2*COS(X1) = -0.3 ;
and so I used following program;


VARIABLES X1, X2,Z;
EQUATIONS EQ1, EQ2,OBJ;
EQ1… 4X2Sin(X1) =e= -0.6 ;
EQ2… 4SQR(X2)-4X2*COS(X1) =e= -0.3 ;
X1.l=0;X2.l=0;X1.up=100;X2.up=100;
OBJ… Z =E= 0;
MODEL LPKKT /OBJ,EQ1,EQ2/;
SOLVE LPKKT USING dnlp minimizing Z;

I am getting output as

LOWER LEVEL UPPER MARGINAL

---- VAR X1 -INF -0.940 100.000 EPS
---- VAR X2 -INF 0.186 100.000 .
---- VAR Z -INF . +INF .

Actual output to get is X1=-0.186&X2=+0.940 ==>Can anybody please
help me in getting correct output

thanx in advance

Abraham


\

Abraham:

  • If GAMS declares a solution feasible then it is VERY likely feasible and
    if it is not what you expect, then look for a reason. A model with Sin and
    Cos can have multiple solutions so you may just have found another solution.

  • If you try to start from a point near your expected solution, for example
    x1.l = -0.2; x2.l = 0.9; you will get another solution, but not the one you
    want:
    LOWER LEVEL UPPER
    MARGINAL

---- VAR X1 -INF -0.1669 100.0000 .
---- VAR X2 -INF 0.9031 100.0000 .
---- VAR Z -INF . +INF .

  • If you compute the residuals using your own point you will find that it is
    not feasible:

scalar res1, res2;
x1.l = -0.186; x2.l = 0.940;
res1 = 4X2.lSin(X1.l) - (-0.6) ;
res2 = 4SQR(X2.l)-4X2.l*COS(X1.l) - (-0.3) ;
display res1, res2 ;

gives:

---- 17 PARAMETER res1 = -0.095
PARAMETER res2 = 0.139

So there is probably an error in your initial model. Good luck.

Arne


Arne Stolbjerg Drud
ARKI Consulting & Development A/S
Bagsvaerdvej 246A, DK-2880 Bagsvaerd, Denmark
Phone: (+45) 44 49 03 23, Fax: (+45) 44 49 03 33, email: adrud@arki.dk

-----Original Message-----
From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On
Behalf Of ABY
Sent: Friday, April 20, 2012 7:31 AM
To: gamsworld
Subject: Solving Simultenous Equations

Hi,

I am new to GAMS and wants to solve two simultenous equations;
4X2Sin(X1) = -0.6
4SQR(X2)-4X2*COS(X1) = -0.3 ;
and so I used following program;


VARIABLES X1, X2,Z;
EQUATIONS EQ1, EQ2,OBJ;
EQ1… 4X2Sin(X1) =e= -0.6 ;
EQ2… 4SQR(X2)-4X2*COS(X1) =e= -0.3 ;
X1.l=0;X2.l=0;X1.up=100;X2.up=100;
OBJ… Z =E= 0;
MODEL LPKKT /OBJ,EQ1,EQ2/;
SOLVE LPKKT USING dnlp minimizing Z;

I am getting output as

LOWER LEVEL UPPER MARGINAL

---- VAR X1 -INF -0.940 100.000 EPS
---- VAR X2 -INF 0.186 100.000 .
---- VAR Z -INF . +INF .

Actual output to get is X1=-0.186&X2=+0.940 ==>Can anybody please help me
in getting correct output

thanx in advance

Abraham

\

“gamsworld” group.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to
gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/gamsworld?hl=en.

\

Hi Abraham,

I agree with Arne. If you want, you may run the following piece of code in MATLAB to verify that your simultaneous equations have several solutions. Attached is also one file where you can easily see there are multiple points where the two surface plots of the equations cross each other (where the solutions exist).

%=============================

%Graphical Visualization
%The solutions of the two equations z1 and z2 is basically at the
%intersection points (i.e. when z1 = z2)
%x=0:0.2:20;
%y=-10:0.2:10;
[x,y] = meshgrid([0:.2:20],[-10:0.2:10]);

z1=(4x.sin(y))+0.6;
surfc(x,y,z1)
colormap hsv
%figure
hold on
z2=4
sqrt(x)-4
x.*cos(y)+0.3;
surfc(x,y,z2)
colormap hsv
%====================================================

Best wishes,
Destin


On Fri, Apr 20, 2012 at 10:46 AM, Arne Stolbjerg Drud wrote:

Abraham:

  • If GAMS declares a solution feasible then it is VERY likely feasible and
    if it is not what you expect, then look for a reason. A model with Sin and
    Cos can have multiple solutions so you may just have found another solution.

  • If you try to start from a point near your expected solution, for example
    x1.l = -0.2; x2.l = 0.9; you will get another solution, but not the one you
    want:
    LOWER LEVEL UPPER
    MARGINAL

---- VAR X1 -INF -0.1669 100.0000 .
---- VAR X2 -INF 0.9031 100.0000 .
---- VAR Z -INF . +INF .

  • If you compute the residuals using your own point you will find that it is
    not feasible:

scalar res1, res2;
x1.l = -0.186; x2.l = 0.940;
res1 = 4X2.lSin(X1.l) - (-0.6) ;
res2 = 4SQR(X2.l)-4X2.l*COS(X1.l) - (-0.3) ;
display res1, res2 ;

gives:

---- 17 PARAMETER res1 = -0.095
PARAMETER res2 = 0.139

So there is probably an error in your initial model. Good luck.

Arne


Arne Stolbjerg Drud
ARKI Consulting & Development A/S
Bagsvaerdvej 246A, DK-2880 Bagsvaerd, Denmark
Phone: (+45) 44 49 03 23, Fax: (+45) 44 49 03 33, email: adrud@arki.dk

-----Original Message-----
From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On
Behalf Of ABY
Sent: Friday, April 20, 2012 7:31 AM
To: gamsworld
Subject: Solving Simultenous Equations

Hi,

I am new to GAMS and wants to solve two simultenous equations;
4X2Sin(X1) = -0.6
4SQR(X2)-4X2*COS(X1) = -0.3 ;
and so I used following program;


VARIABLES X1, X2,Z;
EQUATIONS EQ1, EQ2,OBJ;
EQ1… 4X2Sin(X1) =e= -0.6 ;
EQ2… 4SQR(X2)-4X2*COS(X1) =e= -0.3 ;
X1.l=0;X2.l=0;X1.up=100;X2.up=100;
OBJ… Z =E= 0;
MODEL LPKKT /OBJ,EQ1,EQ2/;
SOLVE LPKKT USING dnlp minimizing Z;

I am getting output as

LOWER LEVEL UPPER MARGINAL

---- VAR X1 -INF -0.940 100.000 EPS
---- VAR X2 -INF 0.186 100.000 .
---- VAR Z -INF . +INF .

Actual output to get is X1=-0.186&X2=+0.940 ==>Can anybody please help me
in getting correct output

thanx in advance

Abraham

\

Visualization.bmp (2.56 MB)

Abraham,

A few added notes to what Arne and Destin already said.

  1. To solve general nonlinear systems of equations on ‘large’ regions (where local scope search may not work) you will probably need a global solver. GAMS offers several such solvers, for your small problem even demo versions are suitable. (I am the author of the LGO solver option, but there are also others.)

  2. It makes a lot of sense to think carefully about variable bound settings in global optimization: the tighter the better.

  3. Your problem could have (actually, it has) multiple solutions, depending on the search region defined. In such cases, you may want to find a specific one e.g. by minimizing the norm of the solution.

  4. You could (perhaps should) check out some global optimization literature. My book “Global Optimization in Action” discusses systems of nonlinear equations and inequalities as an important area of application.

Best wishes,

Janos


Janos D. Pinter, PhD, DSc
Proprietor & Research Scientist
Pinter Consulting Services, Inc., Canada
http://www.pinterconsulting.com
janos.d.pinter@gmail.com



On Fri, Apr 20, 2012 at 2:31 AM, ABY wrote:

Hi,

I am new to GAMS and wants to solve two simultenous equations;
4X2Sin(X1) = -0.6
4SQR(X2)-4X2*COS(X1) = -0.3 ;
and so I used following program;


VARIABLES X1, X2,Z;
EQUATIONS EQ1, EQ2,OBJ;
EQ1… 4X2Sin(X1) =e= -0.6 ;
EQ2… 4SQR(X2)-4X2*COS(X1) =e= -0.3 ;
X1.l=0;X2.l=0;X1.up=100;X2.up=100;
OBJ… Z =E= 0;
MODEL LPKKT /OBJ,EQ1,EQ2/;
SOLVE LPKKT USING dnlp minimizing Z;

I am getting output as

LOWER LEVEL UPPER MARGINAL

---- VAR X1 -INF -0.940 100.000 EPS
---- VAR X2 -INF 0.186 100.000 .
---- VAR Z -INF . +INF .

Actual output to get is X1=-0.186&X2=+0.940 ==>Can anybody please
help me in getting correct output

thanx in advance

Abraham

\

To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.



\





\

Best wishes,

Janos


Janos D. Pinter, PhD, DSc

Proprietor & Research Scientist
Pinter Consulting Services, Inc., Canada
http://www.pinterconsulting.com

Adjunct Professor
Ozyegin University, Istanbul, Turkey
http://www.ozyegin.edu.tr/Default.aspx?lang=en-US

114 Stoneybrook Court
Halifax NS, Canada B3M 3J7
Tel. +1-(902)-445-3478
janos.d.pinter@gmail.com

\

To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.