# How can I get output from Reduce assigned to a variable? [closed]

I use Reduce to solve an 3rd order equation, and the output is given as the OR'd combination the solution variable. Normally, I can do a replacement to assign the value to a variable, but that doesn't work on Reduce. I found that I need to use ToRules to do so, but I still can't get it to work.

Vout = Vin/(C1*C2*L1*R1*s^3 + C1*R1*s + C2*L1*s^2 + C2*R1*s + 1)
s = I ω;
values = {
R1 -> 2000,
C1 -> 10e-9,
L1 -> 500u,
C2 -> 1.2n
};
sol2 = Reduce[ComplexExpand[Im[Vout/Vin /. values]] = =0, ω]


Here's what I see in my notebook:

Normally, I'd do

ω = (ω /. sol2[[3])


to grab the 3rd item from the similar list resulting from Solve. However, Reduce doesn't provide a list, so it doesn't work. How do I use ToRules correctly? Or is there another way to grab a specific output from the expression returned by Reduce?

• Have you seen ToRules? – Michael E2 Oct 15 '20 at 18:29
• Try {ToRules[sol2]}[[3]] instead. – Sjoerd Smit Oct 15 '20 at 18:34
• Also \[Omega] /. Solve[sol2, \[Omega]] – Jason B. Oct 15 '20 at 19:04
• Or just use Solve, e.g., sol2 = Solve[ComplexExpand[Im[Vout/Vin /. (values // Rationalize)]] == 0, \[Omega]]. In some cases you may wish/need to add the option Method -> Reduce – Bob Hanlon Oct 15 '20 at 19:12
• @Sjoerd Smit --> that worked! thanks! If you offer the solution as an answer, I can give you the proper credit. – jrive Oct 15 '20 at 20:05

It is recommend to use Rationalize@1.2 instead of 1.2 in Reduce or Solve

Clear["*"];
Vout = Vin/(C1*C2*L1*R1*s^3 + C1*R1*s + C2*L1*s^2 + C2*R1*s + 1);
s = I ω;
values = {R1 -> 2000, C1 -> 10 e - 9, L1 -> 500 u,
C2 -> Rationalize@1.2 n};
sol2 = Reduce[ComplexExpand[Im[Vout/Vin /. values]] == 0, ω]
sol3 = Solve[ComplexExpand[Im[Vout/Vin /. values]] == 0, ω]


Maybe you use the old version of Mathematica. Here we test the method provided by @SjoerdSmit

sol2 // ToRules // List

(* {{u -> 0,
e -> -(3/50) (-15 + 2 n)}, {ω -> -(Sqrt[-45 + 50 e + 6 n]/
Sqrt[-27000 n u + 30000 e n u])}, {ω ->
Sqrt[-45 + 50 e + 6 n]/Sqrt[-27000 n u + 30000 e n u]}, {n -> 0,
e -> 9/10}, {ω -> 0}}
*)


I've never used ToRules myself, but it looks like it's a very old function. Anyway, it seems like it has the strange convention to convert Or (||) into a Sequence:

ToRules[x == 1 || y == 1]
(* Sequence[{x -> 1}, {y -> 1}] *)


This is rather unusual; hardly any function in WL ever returns a Sequence. And (&&) , on the other hand, gets converted to a List:

ToRules[x == 1 && y == 1]
(* {x -> 1, y -> 1} *)


So it looks like you're expected to wrap the returned value of ToRules in a list in order to get something similar to what Solve returns (a list of lists of rules).

Thus, to access the 3rd solution, you need:

{ToRules[sol2]}[[3]]
`