Solve a system of polynomial equations - getting different results using Symbolic Math Toolbox of MATLAB and Sage
I am trying to solve the following system of equations:
eq1 = 0.8 - 1.8352657742116e-5*sqrt(x1*(3071.1916*x2 + (2.19736842105263e-5 *x3 - 0.378721571752863)*(3069.38078875823*x1 - 802.539479414006*x2 - 802.539479414006*x3 + 1187113.71566341))/(2.19736842105263e-5*x3 - 0.378721571752863))
eq2 = (-0.00117574932506308*x2*sqrt(-(0.039945461792316*x2 + 0.039945461792316*x3 - 71.5306505072653)*(3071.1916*x2 + 32.9605263157895*x3 - 568082.357629294)/(2.19736842105263e-5*x3 - 0.378721571752863)) + 1.8352657742116e-5*sqrt(x1*(3071.1916*x2 + (2.19736842105263e-5*x3 - 0.378721571752863)*(3069.38078875823*x1 - 802.539479414006*x2 - 802.539479414006*x3 + 1187113.71566341))/(2.19736842105263e-5*x3 - 0.378721571752863))*(x2 + x3))/(x2 + x3)
eq3 = (0.007585843252*x2*(x2 + x3) - 0.00117574932506308*x3*sqrt(-(0.039945461792316*x2 + 0.039945461792316*x3 - 71.5306505072653)*(3071.1916*x2 + 32.9605263157895*x3 - 568082.357629294)/(2.19736842105263e-5*x3 - 0.378721571752863))*(2.19736842105263e-5*x3 - 0.378721571752863) + (x2 + x3)*(2.19736842105263e-5*x3 - 0.378721571752863)*(-0.00198227251415259*x2 - 0.00198227251415259*x3 + 42.4521708776886))/((x2 + x3)*(2.19736842105263e-5*x3 - 0.378721571752863))
When I use Symbolic Math Toolbox in Matlab through the following command:
[x1_bar,x2_bar,x3_bar] = solve(eqs,[x1,x2,x3], 'MaxDegree',4);
we get the following results:
x1_bar
ans =
1.0e+04 *
-0.0116 + 0.0000i
0.5338 + 0.0000i
-0.0232 + 0.0000i
0.2669 + 0.0000i
-0.0047 + 0.0000i
1.3191 + 0.0000i
-0.0321 - 0.5445i
0.0007 - 0.0113i
-0.0321 + 0.5445i
0.0007 + 0.0113i
-0.0012 + 0.0000i
5.1569 + 0.0000i
x2_bar =
1.0e+03 *
1.9653 + 0.0000i
1.9653 + 0.0000i
0.2480 + 0.0000i
0.2480 + 0.0000i
-0.6495 + 0.0000i
-0.6495 + 0.0000i
-0.1794 + 0.2236i
-0.1794 + 0.2236i
-0.1794 - 0.2236i
-0.1794 - 0.2236i
-0.0393 + 0.0000i
-0.0393 + 0.0000i
x3_bar =
1.0e+04 *
-0.0174 + 0.0000i
-0.0174 + 0.0000i
0.6522 + 0.0000i
0.6522 + 0.0000i
4.8817 + 0.0000i
4.8817 + 0.0000i
0.2382 + 2.1159i
0.2382 + 2.1159i
0.2382 - 2.1159i
0.2382 - 2.1159i
1.7273 + 0.0000i
1.7273 + 0.0000i
When I try to solve this problem with Sage using:
S = solve([eq1,eq2,eq3],x1,x2,x3)
I obtain the following results:
[{x1: -321.3551367159828 - 5445.311876550251*I,
x2: -179.359654094372 - 223.5730259195566*I,
x3: 2381.999033439763 - 21159.38999334523*I},
{x1: 6.685918535164614 - 113.2918302698741*I,
x2: -179.359654094372 - 223.5730259195566*I,
x3: 2381.999033439763 - 21159.38999334523*I},
{x1: 6.685918535164623 + 113.2918302698741*I,
x2: -179.359654094372 + 223.5730259195566*I,
x3: 2381.999033439763 + 21159.38999334523*I},
{x1: -321.3551367159836 + 5445.311876550251*I,
x2: -179.359654094372 + 223.5730259195566*I,
x3: 2381.999033439763 + 21159.38999334523*I}]
I tried also to use the PolynomialRing but it is failing to solve the problem.
EDIT : Here are the raw equations with the original quantities:
eq1 =w_G_a_in - K_a*sqrt((x1*(R*T_a + g*L_a*M_G_a)*((g*L_a*x1)/V_a -
(g*L_r*(x2 + x3 - L_bh*S_bh*rho_L))/V_r - F_riser + (R*T_a*x1)/(V_a*M_G_a)
+ (R*T_r*rho_L*x2)/(M_G_r_t*(x3 - V_r*rho_L + L_bh*S_bh*rho_L))))/(R*T_a*V_a))
eq2 =K_a*sqrt((M_G_a*((g*L_a*x1)/V_a + (R*T_a*x1)/(V_a*M_G_a))*((g*L_a*x1)/
V_a - (g*L_r*(x2 + x3 - L_bh*S_bh*rho_L))/V_r - F_riser + (R*T_a*x1)/(V_a*M_G_a)
+ (R*T_r*x2)/(M_G_r_t*(L_bh*S_bh - V_r + x3/rho_L))))/(R*T_a))-(GOR*PI*(2*F_riser - P_r + g*L_bh*rho_L + (g*L_r*(x2 + x3 - L_bh*S_bh*rho_L))/V_r
- (R*T_r*x2)/(M_G_r_t*(L_bh*S_bh - V_r + x3/rho_L))))/(GOR + 1) - (K_r*u1*x2*
sqrt(-((P0 + (R*T_r*x2)/(M_G_r_t*(L_bh*S_bh - V_r + x3/rho_L)))*(x2 + x3 - L_bh*S_bh*rho_L))/V_r))/(x2 + x3)
eq3 =PI*(GOR/(GOR + 1) - 1)*(2*F_riser - P_r + g*L_bh*rho_L + (g*L_r*(x2 + x3
- L_bh*S_bh*rho_L))/V_r - (R*T_r*x2)/(M_G_r_t*(L_bh*S_bh - V_r + x3/rho_L)))
- (K_r*u1*x3*sqrt(-((P0 + (R*T_r*x2)/(M_G_r_t*(L_bh*S_bh - V_r + x3/rho_L)))*(x2 + x3 - L_bh*S_bh*rho_L))/V_r))/(x2 + x3)
Please take the time to type your questions in a machine-readable for : your equations are full of implicit products (usually a really bad idea...).
Your equations are not polynomial. For exemple, the second has the form :
√(c18x2+c8x3+c13)(c5x2+c5x3+c3)c15x3+c0c6x2+c4(x2+x3)√(c16x1+c7x2+c7x3+c10)(c15x3+c0)+c18x2c15x3+c0x2+x3
However,such equations can be generalized to polynomials : see
slelievre
's answer to this question.The question was entered with machine readable input, but not formatted as code so the
*
for products were interpreted as markdown formatting for "italics". That's why it looked full of implicit products and italics!Thanks Emmanuel and SLelievre for your quick answer.
Really sorry for the formatting issue. I am new to sage and this is the first time I post a question here.
So after taking a quick look on the proposed solution by SLelievre, I guess we need to transform these equations to ploynomials and then use groebner_basis() to solve it rather than roots(). Am I right?
Thanks,
We want the locus where all three expressions given by
eq1
,eq2
,eq3
are zero.We might as well remove denominators.
For the second equation, starting from the expression given by @Emmanuel Charpentier,