# Work with equation involving different independent variables [closed]

Sometimes I will use an equation, for example, imagine the old chemistry ideal gas law, PV=nRT. Depending on the situation I may want to use different variables as the independent variable. So, for example, in the case of the ideal gas law there are 4 different possible independent variables.

What is a good way to manage this situation and set it up in Mathematica so I can easily compute any particular variable in terms of the others in a literate way?

## closed as unclear what you're asking by chuy, Feyre, corey979, yohbs, MarcoBJan 19 '17 at 19:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• V /. Solve[P V == n R T, V][]? – Feyre Jan 19 '17 at 14:01
• @Feyre I know I can repetitively solve the same equation over and over again. I am hoping there is a more elegant solution. – Tyler Durden Jan 19 '17 at 14:26
• What kind of thing do you want? – Feyre Jan 19 '17 at 14:33
• It is not quite clear what you're asking. Please elaborate by a specific example. In the meanwhile I'm voting to close this question. – yohbs Jan 19 '17 at 16:18

## 2 Answers

ClearAll[gasLaw];

gasLaw[var_Symbol, opts : OptionsPattern[]] :=
Solve[P V == n R T, var, Reals,
FilterRules[{opts}, Options[Solve]]][]

gasLaw[P]

(*  {P -> (n R T)/V}  *)

Flatten[gasLaw /@ Variables[Level[P V == n R T, {-1}]]]

(*  {n -> (P V)/(R T), P -> (n R T)/V, R -> (P V)/(n T), T -> (P V)/(n R),
V -> (n R T)/P}  *)


Do you mean something like this ?

var = n;
Solve[P V == n R T, var]