That code looks familiar. ;-)
There are many different ways to approach this, as you can see from the answers you're getting. Fundamentally it is important to learn how to manipulate arbitrary expressions rather than carrying around specific bits of code or you will end up in the trap of cargo cult programming.
You have output that looks like this:
r1 = Minimize[{x - 2 y^2, 1500 >= x >= y >= 0}, {x, y}]
r2 = FindRoot[{v - Sin[u] == 0, v + u == 30}, {u, 0}, {v, 20}]
{-4498500, {x -> 1500, y -> 1500}}
{u -> 30.675, v -> -0.674984}
The first output is a list of two elements: a numeric value and a list of replacement rules.
The second output is simply a list of rules.
My original method was used to extract both the numeric value and the list of rules from the first result, i.e.:
{x, y, #} /. #2 & @@ r1
Assuming no conflict between the replacements you can simply string together additional ReplaceAll
operations:
{x, y, u, v, #} /. #2 & @@ r1 /. r2
{1500, 1500, 30.675, -0.674984, -4498500}
Note that because of the order of operations the code above parses as:
({x, y, u, v, #} /. #2 & @@ r1) /. r2
(r1 /. r2)
would not produce the result you intend. You could also write:
{x, y, u, v, #} /. #2 /. r2 & @@ r1
These methods work fine for a one-off operation but there is another format you may wish to use: convert all results to a standard list of replacement rules. We need to convert the output of Minimize
into this form, so I will use the label "min"
for the first value:
r1 = Join[{"min" -> #}, #2] & @@ r1
{"min" -> -4498500, x -> 1500, y -> 1500}
From here you have many options. You can simply apply both sets of rules in sequence:
{x, y, u, v, "min"} /. r1 /. r2
{1500, 1500, 30.675, -0.674984, -4498500}
Or you could join the rule lists for ease of later application:
rules = Join[r1, r2]
{"min" -> -4498500, x -> 1500, y -> 1500, u -> 30.675, v -> -0.674984}
You can even use some more exotic methods such as OptionValue
which can be useful in certain cases such as handling defaults or issuing a message when a value is missing:
OptionValue[{r1, r2}, {x, y, u, v, "min"}]
{1500, 1500, 30.675, -0.674984, -4498500}