Solve returns different answers to the same question
Show older comments
I am trying to use solve() to solve a system of 4 equations for 4 variables, using the following code.
syms x1 x2 x3 x4
vars = [x1 x2 x3 x4];
eqns = [ x1 == 30/7 - 1/(x3+x4), x2==30/7 - 1/(x3+x4), x3== 10/3 - 1/(x1+x2+x4), x4==10/3 - 1/(x1+x2+x3) ];
C = solve(eqns, vars);
Then vpa(C.x1) returns:
ans =
-1.6666666666666666666666666666667
-1.6666666666666666666666666666667
4.1316999594422134359804216941161 - 2.5330953622691428389795980612384e-39i
4.343827578149360853360217735709 + 9.3940138280508998241066580657853e-40i
0.095901033836997139230789141603439 + 1.6227020204672685655672638821872e-39i
Which is the correct solution. However, when the same problem is reformulated using:
eqns = [ x1 == 10/3 - 1/(x2+x3+x4), x2==10/3 - 1/(x1+x3+x4), x3== 30/7 - 1/(x1+x2), x4==30/7 - 1/(x1+x2) ];
Note that although the names of the variables and the order they are entered is different, this system is identical to the original. Then vpa(C.x4) (which should contain the same solutions as C.x1) instead returns:
ans =
-1.6666666666666666666666666666667
-1.6666666666666666666666666666667
4.343827578149360853360217735709
0.095901033836997139230789141603439
4.1316999594422134359804216941161
This is presenting a problem for me since somehow it seems to be losing the imaginary portion of each of the complex solutions, only in the second scenario. Why is this happening and how can I fix it so that it is returning the full complex solutions?
Accepted Answer
More Answers (0)
Categories
Find more on Equation Solving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!