Solving a set of nonlinear equations Topic is solved

Problems with modeling
Post Reply
argon
User
User
Posts: 3
Joined: 1 year ago

Solving a set of nonlinear equations

Post by argon »

I try to solve this system, although I can solve it in Matlab, here I cannot. I am new to GAMS and I try to solve it like this:

Code: Select all


variables z_1, z_2, z_3, z_4, z_5,
          y_12, y_23,y_34, y_41, y_45,
          x_1, x_2, x_3, x_4, x_5;

equations eq1, eq2, eq3, eq4, eq5,
          eq6, eq7, eq8, eq9, eq10
          eq11, eq12, eq13, eq14, eq15 ;
eq1..     0 =e= x_1 + y_41 - y_12 ;
eq2..     0 =e= x_2 + y_12 - y_23 ;
eq3..     0 =e= x_3 + y_23 - y_34 ;
eq4..     0 =e= x_4 + y_34 - y_41 - y_45 ;
eq5..     0 =e= x_5 + y_45;
eq6..     0 =e= 0.1294   * (y_12 * abs(y_12)) - ( z_1**2 - z_2**2 );         
eq7..     0 =e= 0.1294   * (y_23 * abs(y_23)) - ( z_2**2 - z_3**2 );
eq8..     0 =e= 0.1294   * (y_34 * abs(y_34)) - ( z_3**2 - z_4**2 );
eq9..     0 =e= 0.1294   * (y_41 * abs(y_41)) - ( z_4**2 - z_1**2 );
eq10..    0 =e= 0.1294   * (y_45 * abs(y_45)) - ( z_4**2 - z_5**2 );
eq11..     0 =e= z_1 - 50;            
eq12..     0 =e= x_2 + 20;          
eq13..     0 =e= x_3 + 40;            
eq14..     0 =e= x_4      ;       
eq15..     0 =e= x_5 + 15;


z_2.l=1; z_3.l=1; z_4.l=1; z_5.l=1;
y_12.l=1; y_23.l=1;y_34.l=1; y_41.l=1; y_45.l=1;
x_1.l=1;

model dummy /all/;

solve dummy using  dnlp minimizing x_1;
So can anyone tell me what is the problem here?
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Solving a set of nonlinear equations

Post by Manassaldi »

Hi, you should use "power(x,2)" instead of "x**2"
Since your system is square, you can also solve using "cns"

Try: solve dummy using cns;

Best

Code: Select all

variables z_1, z_2, z_3, z_4, z_5,
          y_12, y_23,y_34, y_41, y_45,
          x_1, x_2, x_3, x_4, x_5;

equations eq1, eq2, eq3, eq4, eq5,
          eq6, eq7, eq8, eq9, eq10
          eq11, eq12, eq13, eq14, eq15 ;
eq1..     0 =e= x_1 + y_41 - y_12 ;
eq2..     0 =e= x_2 + y_12 - y_23 ;
eq3..     0 =e= x_3 + y_23 - y_34 ;
eq4..     0 =e= x_4 + y_34 - y_41 - y_45 ;
eq5..     0 =e= x_5 + y_45;
eq6..     0 =e= 0.1294   * (y_12 * abs(y_12)) - ( power(z_1,2) - power(z_2,2) );
eq7..     0 =e= 0.1294   * (y_23 * abs(y_23)) - ( power(z_2,2) - power(z_3,2) );
eq8..     0 =e= 0.1294   * (y_34 * abs(y_34)) - ( power(z_3,2) - power(z_4,2) );
eq9..     0 =e= 0.1294   * (y_41 * abs(y_41)) - ( power(z_4,2) - power(z_1,2) );
eq10..    0 =e= 0.1294   * (y_45 * abs(y_45)) - ( power(z_4,2) - power(z_5,2) );
eq11..     0 =e= z_1 - 50;
eq12..     0 =e= x_2 + 20;
eq13..     0 =e= x_3 + 40;
eq14..     0 =e= x_4      ;
eq15..     0 =e= x_5 + 15;


z_2.l=1; z_3.l=1; z_4.l=1; z_5.l=1;
y_12.l=1; y_23.l=1;y_34.l=1; y_41.l=1; y_45.l=1;
x_1.l=1;

model dummy /all/;

solve dummy using  dnlp minimizing x_1;
argon
User
User
Posts: 3
Joined: 1 year ago

Re: Solving a set of nonlinear equations

Post by argon »

Thanks, both can solve my problem.
Post Reply