User Tools

Site Tools


gams:using_gams_for_solving_square_nonlinear_systems

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
gams:using_gams_for_solving_square_nonlinear_systems [2007/10/20 07:14]
Franz Nelissen
gams:using_gams_for_solving_square_nonlinear_systems [2020/05/28 08:37] (current)
Michael Bussieck
Line 4: Line 4:
 and ''​i = 1,..., n''​.//​ and ''​i = 1,..., n''​.//​
  
-Contributed by [[tom@mpsge.org|Tom Rutherford]] to the [[http://​www.gams.com/​maillist/​gams_l.htm|GAMS-User List]]: ​There are three basic approaches ​ available for solving square+There are three basic approaches ​ available for solving square
 nonlinear systems under GAMS: nonlinear systems under GAMS:
  
 1) Formulate as a NLP (nonlinear program) with a irrelevant objective function:​\\ ​ 1) Formulate as a NLP (nonlinear program) with a irrelevant objective function:​\\ ​
-      max anything s.t. f_i(x) = 0 i=1,...,n+      max anything ​ 
 +      ​s.t. f_i(x) = 0 i=1,...,n 
 +      xlo_i <= x_i <= xup_i 
  
 2) Formulate as an MCP (mixed compelementarity problem) without bounds:\\ 2) Formulate as an MCP (mixed compelementarity problem) without bounds:\\
-      f_i(x) = 0 i=1,...,n''​+      f_i(x) = 0 i=1,...,n
       -inf <= x_i <= +inf i=1,...,n       -inf <= x_i <= +inf i=1,...,n
  
Line 20: Line 22:
 Approaches (1) and (3) offer some advantages if the functions you are using are undefined for some values of x. You can then apply upper and lower bounds which assure that the algorithm does not wander off, but even with bounds you may not be assured of finding solution if the functions are not nicely behaved (monotone, P, etc.). Approaches (1) and (3) offer some advantages if the functions you are using are undefined for some values of x. You can then apply upper and lower bounds which assure that the algorithm does not wander off, but even with bounds you may not be assured of finding solution if the functions are not nicely behaved (monotone, P, etc.).
 <​code>​ <​code>​
-$TITLE THREE METHODS FOR SOLVING NONLINEAR SYSTEMS WITH GAMS +$title Three methods for solving nonlinear systems with gams 
-VERY SIMPLE NONLINEAR SYSTEM+very simple nonlinear system
-SET I /I1*I10/; ALIAS (I,J); +Set i /i1*i10/; alias (i,j); 
-PARAMETER SOLUTION SOLUTIONS FROM ALTERNATIVE FORMULATIONS;​ +Parameter 
-PARAMETER A(IQUADRATIC PARAMETER +    ​solution(i,*'​solutions from alternative formulations'​ 
-C(I,JLINEAR PARAMETER +    a(i)          '​quadratic parameter'​ 
-B(IINTERCEPT PARAMETER+    c(i,j       '​linear parameter'​ 
-B(I) = UNIFORM(0,1); +    b(i         '​intercept parameter'​
-C(I,J) = UNIFORM(0,1); + 
-A(I) = UNIFORM(0,1); +b(i) = uniform(0,1); 
-VARIABLES X(IUNKNOWN VECTOR X+c(i,j) = uniform(0,1); 
-* FUNCTION F DEFINES THE SYSTEM OF EQUATIONS WHICH +a(i) = uniform(0,1); 
-APPLY IN ALL FORMULATIONS+ 
-EQUATIONS F(ICONSTRAINTS ON X+Variables 
-F(I).. +    x(i'​unknown vector x' 
-SUM(JC(I,J) * X(J) + A(J) * X(J) * X(J)) - B(I) =E= 0; +    obj  'dummy objective'​
-* (1) FORMULATION AS A CONSTRAINED NONLINEAR SYSTEM+ 
-MODEL CNS_NLSYS ​/F/; +function f defines the system of equations which apply in all formulations
-X.L(I) = 1; +Equations 
-SOLVE CNS_NLSYS USING CNS; +    f(i  '​constraints on x' 
-SOLUTION(I,"CNS") = X.L(I); +    objdef '​defines the dummy objective'​
-* (2) FORMULATION AS AN MIXED COMPLEMENTARITY PROBLEM+f(i)..   sum(jc(i,j) * x(j) + a(j) * x(j) * x(j)) - b(i) =e= 0; 
-MODEL MCP_NLSYS ​/F.X/; +objdef.. obj =e= 1; 
-X.L(I) = 1; + 
-OPTION MCP=MILES; +* (1) formulation as a nonlinear program
-SOLVE MCP_NLSYS USING MCP; +model nlp_nlsys ​/objdef, f/; 
-SOLUTION(I,"MCP") = X.L(I); +x.l(i) = 1; solve nlp_nlsys using nlp maximizing objsolution(i,"nlp") = x.l(i); 
-* (3) FORMULATION AS A NONLINEAR PROGRAM+* (2) formulation as an mixed complementarity problem
-VARIABLE OBJ DUMMY OBJECTIVE;​ +model mcp_nlsys ​/f.x/; 
-EQUATION OBJDEF DEFINES THE DUMMY OBJECTIVE;​ +x.l(i) = 1; solve mcp_nlsys using mcpsolution(i,"mcp") = x.l(i); 
-OBJDEF.. OBJ =E= 1+* (3) formulation as a constrained nonlinear system
-X.L(I) = 1; +model cns_nlsys /f/
-MODEL NLP_NLSYS /OBJDEF, F/; +x.l(i) = 1; solve cns_nlsys using cnssolution(i,"cns") = x.l(i); 
-SOLVE NLP_NLSYS USING NLP MAXIMIZING OBJ; +print out a comparison
-SOLUTION(I,"NLP") = X.L(I); +option solution:8; display solution
-PRINT OUT A COMPARISON+$onText 
-OPTION SOLUTION:8; +the program should produce: 
-DISPLAY SOLUTION+ 
-$ontext +----     35 PARAMETER ​solution ​ solutions from alternative formulations 
-The program should produce: +            ​nlp         ​mcp         ​cns 
-----     38 PARAMETER ​SOLUTION ​ SOLUTIONS FROM ALTERNATIVE FORMULATIONS +i1  ​-0.82541120 -0.82541120 -0.82541120 
-            ​CNS         ​MCP         ​NLP +i2   0.42506471 ​ ​0.42506470 ​ 0.42506470 
-I1  ​-0.82541120 -0.82541120 -0.82541120 +i3  ​-0.29439840 -0.29439840 -0.29439840 
-I2   0.42506470 ​ ​0.42506470 ​ 0.42506471 +i4  -0.46446260 ​-0.46446261 -0.46446261 
-I3  ​-0.29439840 -0.29439840 -0.29439840 +i5  -0.58034819 ​-0.58034820 -0.58034820 
-I4  -0.46446261 ​-0.46446261 -0.46446260 +i6   0.16156813 ​ ​0.16156815 ​ 0.16156815 
-I5  -0.58034820 ​-0.58034820 -0.58034819 +i7  -1.00001461 ​-1.00001459 -1.00001459 
-I6   0.16156815 ​ ​0.16156815 ​ 0.16156813 +i8   0.11500797 ​ 0.11500797 ​ 0.11500797 
-I7  -1.00001459 ​-1.00001459 -1.00001461 +i9   0.44654506 ​ 0.44654506 ​ 0.44654506 
-I8   0.11500797 ​ 0.11500797 ​ 0.11500797 +i10  0.64782839 ​ ​0.64782840 ​ 0.64782840 
-I9   0.44654506 ​ 0.44654506 ​ 0.44654506 +$offText
-I10  0.64782840 ​ ​0.64782840 ​ 0.64782839 +
-$offtext+
 </​code>​ </​code>​
IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/using_gams_for_solving_square_nonlinear_systems.txt · Last modified: 2020/05/28 08:37 by Michael Bussieck