MATLAB: Symbolic equation system solving with a lot of simple equations

equation solvingMATLABsolvesymbolic equation solvingsyms

I have got a lot of very simple symbolic equations and i want to solve the equation system for the vars but for some reason i cannot succed in it. Here is an example:
syms u1 u2 I1 I2 I3 I4 C1 C2 R1 R2 a b e1 e2 e3 e4 e5 e6 e7 e8 e9 e10 e11 e12 e13 e14 e15 e16 f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 f16 dx1 dx2 dx3 dx4 dx5 dx6 X1 X2 X3 X4 X5 X6
eqns = [e1==u1, e1==e2+e3+e4, f1==f2, f2==f3, f3==f4, e2==R1*f2, e3==dx1, f3==X1/I1, e4==a*f5, f4==e5/a, e5==e6+e7+e8, f5==f6, f6==f7, f7==f8, e6==R2*f6, e7==dx2, f7==X2/I2, e8==b*e9, f8==f9/b, e9==e10, e10==e11, f9==f10+f11, e10==X3/C1, f10==dx3, e11==e12+e13+e14, f11==f12, f12==f13, f13==f14, e12==u2, e13==dx4, f13==X4/I3, e14==e15, e15==e16, f14==f15+f16, e15==X5/C2, f15==dx5, e16==dx6, f16==X6/I4];
var = [dx1 dx2 dx3 dx4 dx5 dx6];
sol=solve(eqns,var)
As you can see i've got a lot of variables too and i want to eliminate all of the e. and f. -s (e1,e2,…e16,f1,f2,…,f16) and get is solved for dx.-es. I can solve it by hand so it shouldn't be an issue with matlab (this is the result: "Empty sym: 0-by-1"), possibly i just missed some important step.
Do you think it is even possible to solve the symbolic equations this way or should i try some different method?

Best Answer

People seem to think that shorthand that makes sense to them is always going ot make sense to a computer.

syms f1 f2 f3 f4

When use the following form, what does MATLAB see?

f1==f2==f3==f4
ans =
((f1 == f2) == f3) == f4

Can we "solve" that problem? What if we added one more equation, that f4==1? That should make the problem well posed.

solve(f1==f2==f3==f4,f4 == 1)
ans = 
  struct with fields:
    f1: [0×1 sym]
    f2: [0×1 sym]

No solution was found.

The problem is YOU understand a transitive shorthand like this: a=b=c=d, to imply that all of them are equal. MATLAB does not take it that way.

Instead, you need to set the problem up with separate equations.

S = solve(f1==f2, f2==f3, f3==f4, f4 == 1)
S = 
struct with fields:
    f1: [1×1 sym]
    f2: [1×1 sym]
    f3: [1×1 sym]
    f4: [1×1 sym]

And we see that S.f1 is what we expect.

S.f1
ans =
1