2
$\begingroup$

Possible Duplicate:
Assign the results from a Solve to variable(s)

In the following example:

Clear[g1, z1, a, g2, z2]
sa = Solve[ g1 == 1 + l z1/(z1^2 + a), a]
sb = Solve[ g2 == 1 - l z2/(z2^2 + b), b] /. z2 -> z1 + l

This gives me solutions for a and b that are in the form

{{ a -> astuff }}
{{ b -> bstuff }}

I want to use this result in a secondary computation, and did so by cut and pasting from the Solve[] results like so

 Solve[ astuff == bstuff, z1 ]

How can I just extract those results without cut and pasting? I don't like the cut and paste dependency since I'd have to redo it all if I make any sort of correction to the first couple identities.

$\endgroup$
  • $\begingroup$ You can use Part to extract the relevant bits. $\endgroup$ – b.gates.you.know.what Dec 15 '12 at 20:06
2
$\begingroup$

You could use ReplaceAll (/.):

Clear[g1, z1, a, g2, z2]
sa = Solve[g1 == 1 + l z1/(z1^2 + a), a]
sb = Solve[g2 == 1 - l z2/(z2^2 + b), b] /. z2 -> z1 + l

Solve[(a /. sa[[1]]) == (b /. sb[[1]]), z1]

Here the /. command is used to manipulate the expressions a and b according to the rules given by sa and sb.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.