# Solving for any one variable in a formula given values for all the others [closed]

Consider the formula for the area of a rectangle. I can write the formula as area[length_, width_] := length*width and plug in numbers for the dimensions and get the area. Also, I could write a formula for finding each specific dimension in terms of the remaining two. My question is this: Is there a way to write a single expression which will do the whole job, that is I can plug in any two of the components of the area formula and have Mathematica return the third?

-

## closed as unclear what you're asking by Artes, bobthechemist, Silvia, rasher, ubpdqnMar 30 at 10:23

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.

Yes, what you ask for can be done with Manipulate. –  m_goldberg Mar 28 at 13:07
maybe it would help if you showed examples of what you expect the syntax to look like. The question title doesn't reflect at all what you are asking by the way. –  george2079 Mar 28 at 13:26
@george2079. The title is my edit, not the OP's original title. It's my best shot at describing what the OP is asking. Since you think it's way off target, please edit it to get it on target. –  m_goldberg Mar 28 at 21:25

rectangle[{r1_Rule, r2_Rule}] :=
(#~Join~First@Solve[ (e1 e2 == area) /. # ,
First@Complement[ {area, e1, e2}, First /@ #] ]) &@{r1, r2}

rectangle[{e2 -> 3, e1 -> 2}]


{e2 -> 3, e1 -> 2, area -> 6}

rectangle[{area -> 12, e1 -> 2}]


{area -> 12, e1 -> 2, e2 -> 6}

-

A variation:

solveMissing[eqn_, vars_] := Solve[
Append[Equal @@@ Cases[vars, {_Symbol, _}], eqn],
Replace[vars, {x_Symbol, _} :> x, 1]]


Examples:

solveMissing[area == length*width, {area, {length, 2}, {width, 4}}]
solveMissing[area == length*width, {{area, 8}, length, {width, 4}}]
(*
{{area -> 8, length -> 2, width -> 4}}
{{area -> 8, length -> 2, width -> 4}}
*)

solveMissing[area == length*width, {area, length, {width, 4}}]
(*
Solve::svars: Equations may not give solutions for all "solve" variables. >>
{{area -> 4 length, width -> 4}}
*)

solveMissing[volume == Pi * radius^2 * height, {{volume, 12 Pi}, radius, {height, 3}}]
(*
{{volume -> 12 π, radius -> -2, height -> 3},
{volume -> 12 π, radius -> 2, height -> 3}}
*)

-