0

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.

Real Noob
  • 219
  • 1
  • 5
  • Something like: Solve[{ax + by == c}, {#}][[1]] & /@ {a, b, c} & – Daniel Huber Oct 26 '20 at 17:15
  • 2
    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. – LouisB Oct 26 '20 at 18:04
  • Thank you very much @LouisB. Is this feature mentioned somewhere in the documentation? – Real Noob Oct 26 '20 at 18:42
  • 1
    @RealNoob: you might like to peruse these learning references: https://mathematica.stackexchange.com/questions/18/where-can-i-find-examples-of-good-mathematica-programming-practice – Moo Oct 26 '20 at 21:41
  • 1
    Thanks @Moo. :) – Real Noob Oct 27 '20 at 01:52

1 Answers1

1

Generalizing the solution provided by LouisB

Clear["Global`*"]

solve[eqn_Equal] := Module[ {$z, vars = Variables[Level[eqn, {-1}]]}, Table[Solve[eqn, {$z}][[1]], {$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 *)

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 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. :) – Real Noob Oct 26 '20 at 18:50
  • 2
    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. – Bob Hanlon Oct 26 '20 at 19:00