In certain problems, we need to solve systems of equations and get results in terms of just selected variables. For example, how could we solve eqn==0
below for c3
and c4
expressed in terms of c1
and c2
only, without a1
or a2
?
eqn = {{c1, c2}, {c1, c3}, {c1, c4}, {c2, c3}}.{a1, a2} - {5, 2, -4, -3}
We can select two equations from the system and solve them for a1
and a2
, then substitute those results back in...
asoln = Solve[eqn[[{1, 2}]] == 0, {a1, a2}];
b = eqn /. asoln;
Solve[b == 0, {c3, c4}]
(* {{c3 -> 1/5 (3 c1 + 2 c2), c4 -> 1/5 (9 c1 - 4 c2)}} *)
This approach works but it requires that we find a subset of equations from which a1
and a2
can be solved for unambiguously, which might be difficult. Is it possible to make Solve[]
eliminate a1
and a2
for us?
Answer
It turns out Solve[]
has a feature that doesn't appear in the online documentation that I could find. A third argument can be added, a list of variables to be eliminated from the solution:
Solve[eqns == 0, {c3, c4}, {a1, a2}]
This yield the same output as above. And I have tested it on problems where solving for a1
and a2
(in order to eliminate them from the system) requires a careful choice of equation subset.
Reduce[]
has an analogous third argument discussed here: Behavior of Reduce with variables as domain
Comments
Post a Comment