2
$\begingroup$

I often have to use Solve and I'm wondering if I there is a more efficient way to specify which variables I have to solve for. Say that I have

eqs = Table[
    x[a, b, c] + y[a, b, c] + a + b + c == 0, {a, 1, 3}, {b, 1, 
     3}, {c, 1, 3}] // Flatten;

If I call Solve[eqs], it will solve for the y in terms of the x. But if I want to solve for the x in terms of the y, instead, I need to call

Solve[eqs, 
 Table[x[a, b, c], {a, 1, 3}, {b, 1, 3}, {c, 1, 3}] // Flatten]

Is there a simpler way, without having to explicitly build the table of the x variable? I tried something like Solve[eqs, x[_,_,_]] or variations of it but couldn't find anything that works. Thanks

$\endgroup$
5
$\begingroup$
Solve[eqs, Cases[eqs, _x, All]]
{{x[1, 1, 1] -> -3 - y[1, 1, 1], x[1, 1, 2] -> -4 - y[1, 1, 2], 
 x[1, 1, 3] -> -5 - y[1, 1, 3], x[1, 2, 1] -> -4 - y[1, 2, 1], 
 x[1, 2, 2] -> -5 - y[1, 2, 2], x[1, 2, 3] -> -6 - y[1, 2, 3], 
 x[1, 3, 1] -> -5 - y[1, 3, 1], x[1, 3, 2] -> -6 - y[1, 3, 2], 
 x[1, 3, 3] -> -7 - y[1, 3, 3], x[2, 1, 1] -> -4 - y[2, 1, 1], 
 x[2, 1, 2] -> -5 - y[2, 1, 2], x[2, 1, 3] -> -6 - y[2, 1, 3], 
 x[2, 2, 1] -> -5 - y[2, 2, 1], x[2, 2, 2] -> -6 - y[2, 2, 2], 
 x[2, 2, 3] -> -7 - y[2, 2, 3], x[2, 3, 1] -> -6 - y[2, 3, 1], 
 x[2, 3, 2] -> -7 - y[2, 3, 2], x[2, 3, 3] -> -8 - y[2, 3, 3], 
 x[3, 1, 1] -> -5 - y[3, 1, 1], x[3, 1, 2] -> -6 - y[3, 1, 2], 
 x[3, 1, 3] -> -7 - y[3, 1, 3], x[3, 2, 1] -> -6 - y[3, 2, 1], 
 x[3, 2, 2] -> -7 - y[3, 2, 2], x[3, 2, 3] -> -8 - y[3, 2, 3], 
 x[3, 3, 1] -> -7 - y[3, 3, 1], x[3, 3, 2] -> -8 - y[3, 3, 2], 
 x[3, 3, 3] -> -9 - y[3, 3, 3]}}

Also (when eqs is linear in x[...] and y[...]):

Solve[eqs /. x -> z] /. z -> x

same result

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.