Search code examples
matlabequationsymbolic-math

matlab symbolic equation gives undetermined result?


not quite sure how the solve function works in matlab? I tried to solve the following symbolic equation, which gives the results with x and y value exchanged when I define different parameters:

T = [0.3, 1.4, 10; 1.3, 0.4, 15; 0.02, 0.01, 1];
 syms x y j i
 q1 = (T(1,1)*x+T(1,2)*y+T(1,3))/(T(3,1)*x+T(3,2)*y+T(3,3))-j;
 q2 = (T(2,1)*x+T(2,2)*y+T(2,3))/(T(3,1)*x+T(3,2)*y+T(3,3))-i;
 [x,y] = solve(sym(q1),sym(q2),x,y);

x =

(50*j - 260*i + 3400)/(5*i + j - 340)
y =

(20*i - 200*j + 1700)/(5*i + j - 340)

T = [0.3, 1.4, 10; 1.3, 0.4, 15; 0.02, 0.01, 1];
 syms j i jj ii
 q1 = (T(1,1)*j+T(1,2)*i+T(1,3))/(T(3,1)*j+T(3,2)*i+T(3,3))-jj;
 q2 = (T(2,1)*j+T(2,2)*i+T(2,3))/(T(3,1)*j+T(3,2)*i+T(3,3))-ii;
 [j,i] = solve(sym(q1),sym(q2),j,i);

j =

(20*ii - 200*jj + 1700)/(5*ii + jj - 340)

i =

(50*jj - 260*ii + 3400)/(5*ii + jj - 340)

any suggestion would be helpful. thanks!


Solution

  • One citation from description of solve function:

    For several equations and an equal number of outputs, the results are sorted in lexicographic order and assigned to the outputs.

    Lexicographic order for the first example is x, y as given in parameters.

    Lexicographic order for the second example is i, j. E.g. it is opposite to the order of parameters.

    It seems function drop order of parameters in function and consider only names of symbolic variables. Before output these names are sorted in alphabetic order.