# Solve equations for multiple variables at same time

Here is an example equation:

Solve[{a*x + b*y == c}, {a}]


It gives me:

a -> (c - b*y)/x


To solve the same equation for b, I need to write:

Solve[{a*x + b*y == c}, {b}]


It will give me:

b -> (c - a*x)/y


Similarly, I will have to repeat the steps for all variables like x and y. Is there an easier to tell Mathematica to solve an equation for all variables one by one?

Thanks.

• Something like: Solve[{ax + by == c}, {#}][] & /@ {a, b, c} & Oct 26 '20 at 17:15
• Flatten@Table[ Solve[a x + b y == c, {z}], {z, {a, b, c, x, y}}] is an easy-to-read method that uses two of the most basic list manipulation functions. Oct 26 '20 at 18:04
• Thank you very much @LouisB. Is this feature mentioned somewhere in the documentation? Oct 26 '20 at 18:42
• @RealNoob: you might like to peruse these learning references: mathematica.stackexchange.com/questions/18/…
– Moo
Oct 26 '20 at 21:41
• Thanks @Moo. :) Oct 27 '20 at 1:52

Generalizing the solution provided by LouisB

Clear["Global*"]

solve[eqn_Equal] := Module[
{$$z, vars = Variables[Level[eqn, {-1}]]}, Table[Solve[eqn, {z}][], {$$z, vars}]]

eqn = a x + b y == c;

sol = solve[eqn]

(* {{a -> (c - b y)/x}, {b -> (c - a x)/y}, {c -> a x + b y}, {x -> (c - b y)/
a}, {y -> (c - a x)/b}} *)


Verifying the solutions

And @@ (eqn /. sol)

(* True *)

• Thanks @Bob. Could you please provide links to some resources where I can learn more about using Mathemtica in such an advanced manner? I am an absolute beginner in Mathemtica and it seems to be a very powerful tool. :) Oct 26 '20 at 18:50
• All the links are built into Mathematica. Highlight any function or operator and click F1 for help. On the documentation paqes look at the examples and look for the links to Tutorials and Related Guides`. Oct 26 '20 at 19:00