I have the function

a = 1 - 3 Sin[theta]^2 Cos[phi]^2;

which I solve for 'phi' when $a=0$

sol = Reduce[a == 0, phi]

which gives me the result

How do I turn this output into a nice list of results for desired values of C[1], much like Solve[ ] would give me, so that I can use Plot[ ] and visualise the functions?

  • $\begingroup$ I fear I may get a 'duplicate' wrist slap as a similar question was answered by m_goldberg on one of my previous posts, and to certain degrees on other posts, but I don't understand well enough to translate to this particular problem :) Hopefully this simple example will help. As always thanks very much for any help. $\endgroup$
    – Tom
    Jun 30, 2014 at 13:06
  • $\begingroup$ Do you mean that you are looking for an entirely automated solution that would work for any Reduce output with no manual intervention? That sounds difficult. Otherwise is {ToRules[sol /. C[1] -> 0]} acceptable here? The manual step was choosing a particular (integer) value for C[1]. $\endgroup$
    – Szabolcs
    Jun 30, 2014 at 13:32
  • $\begingroup$ That's great @Szabolcs. Neat simple solution I was hoping for. What If I wanted a list of all the solutions for values of C[1] say from 1 to 50? $\endgroup$
    – Tom
    Jun 30, 2014 at 13:42
  • $\begingroup$ Not sure what's simplest in that case ... use a Table? Can't really think of anything simpler than that. $\endgroup$
    – Szabolcs
    Jun 30, 2014 at 13:44

2 Answers 2


ToRules is useful here.

If we manually set a value to the parameter C[1], we can convert the remaining expression to a list of rules similar to what Solve would return:

In[5]:= rules = {ToRules[sol /. C[1] -> 0]}

Out[5]= {{phi -> -ArcCos[-(Csc[theta]/Sqrt[3])]}, {phi -> ArcCos[-(Csc[theta]/Sqrt[3])]}, 
         {phi -> -ArcCos[Csc[theta]/Sqrt[3]]}, {phi -> ArcCos[Csc[theta]/Sqrt[3]]}}

Notice that ToRules removed the Sin[theta] != 0 condition, but it would remove the C[1] ∈ Integers condition if we don't make it go away manually. I do not know (and did not check) when precisely it will remove any conditions. So in more general applications this is something to pay attention to.

Plot[phi /. rules, {theta, -5, 5}]

An alternative approach here is to use Solve, which returns the same solution (in recent versions!) as Reduce, but in a different form:

Solve[a == 0, phi]
(* {{phi -> 
   ConditionalExpression[-ArcCos[-(Csc[theta]/Sqrt[3])] + 
     2 π C[1], C[1] ∈ Integers]}, {phi -> 
   ConditionalExpression[ArcCos[-(Csc[theta]/Sqrt[3])] + 2 π C[1],
     C[1] ∈ Integers]}, {phi -> 
   ConditionalExpression[-ArcCos[Csc[theta]/Sqrt[3]] + 2 π C[1], 
    C[1] ∈ Integers]}, {phi -> 
   ConditionalExpression[ArcCos[Csc[theta]/Sqrt[3]] + 2 π C[1], 
    C[1] ∈ Integers]}} *)

If Solve does not generate full conditions by default, as Reduce would, we can use the option Solve[..., Method -> Reduce] to force it to do so.

To make all these ConditionalExpressions go away, we can use Normal:

sol2 = Normal@Solve[a == 0, phi]
(* {{phi -> -ArcCos[-(Csc[theta]/Sqrt[3])] + 
    2 π C[1]}, {phi -> 
   ArcCos[-(Csc[theta]/Sqrt[3])] + 
    2 π C[1]}, {phi -> -ArcCos[Csc[theta]/Sqrt[3]] + 
    2 π C[1]}, {phi -> ArcCos[Csc[theta]/Sqrt[3]] + 2 π C[1]}} *)

Notice that this retained C[1], but dropped the condition. Now we can do

Block[{C}, Join @@ Table[phi /. sol2, {C[1], -5, 5}]]

to have a table of solutions corresponding to $C_1 \in \{-5, -4, \ldots, 4, 5\}$. Block was needed to temporarily lift the protection from C.

Using Solve doesn't give anything new here, it's just a different way of achieving the same results. It may be more or less convenient than Reduce.


Respecting generated conditions is important. In this particular equation (which could be solved by hand and the conditions are clear from the equation. You can access the solutions in a number of ways (e.g. using rules from Solve). Here is just one way:

a = 1 - 3 Sin[theta]^2 Cos[phi]^2;
sol = Reduce[a == 0, phi]
solc = sol /. Equal[x_, y_] :> Rule[x, y];
funs = Cases[solc, Rule[phi, x_] :> x, Infinity] /. C[1] -> 0
Plot[funs, {theta, 0, 2 Pi}, PlotStyle -> {Red, Green, Blue, Orange}]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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