answer == Real1 || answer == Real2
or
answer == Real3
, the type can change from one formula to another.
I need the Reals, and put them all in a list. The problem is getting all the
reals, without knowing which type I deal with, it should be able to be done
fast.
I tried making a list of the returned adres, and then using
Cases[list, _Real, Infinity] and using Select[list,NumericQ] but both do not
give me the answer I require.
How can I get the answer I require e.g. something like {Real1,Real2,Real3}
What about the following?
sols = Reduce[x^4 == 4]
--> x == -Sqrt[2] || x == (-I)*Sqrt[2] || x == I*Sqrt[2] || x == Sqrt[2]
Select[x /. {ToRules[sols]}, Im[Chop[#1]] == 0 & ]
--> {-Sqrt[2], Sqrt[2]}
Regards,
Jean-Marc
Actually, it would very helpful to post your equation.
Anyway, I believe the following will be interesting for you.
First I generate a 4th degree polynomial:
In[1]:=
InputForm[pol=Apply[Plus,Table[Random[Integer,{1,10}]x^i,{i,0,4}]]]
Out[1]//InputForm=
10 + x + 3*x^2 + 7*x^3 + x^4
Using Reduce, I get:
In[2]:=
Reduce[pol\[Equal]0,x,Reals]//InputForm
Out[2]//InputForm=
x == Root[10 + #1 + 3*#1^2 + 7*#1^3 + #1^4 & , 1, 0] || x == Root[10 +
#1 + 3*#1^2 + 7*#1^3 + #1^4 & , 2, 0]
Now I use {ToRules[%]} obtaing:
In[3]:=
{ToRules[%]}//InputForm
Out[3]//InputForm=
{{x -> Root[10 + #1 + 3*#1^2 + 7*#1^3 + #1^4 & , 1, 0]}, {x -> Root[10
+ #1 + 3*#1^2 + 7*#1^3 + #1^4 & , 2, 0]}}
In[4]:=
?ToRules
ToRules[eqns] takes logical combinations of equations, in the form
generated \
by Roots and Reduce, and converts them to lists of rules, of the form \
produced by Solve. More...
To get the solutions in the form {Real1,Real2}, I simply use:
In[5]:=
x/.%%//InputForm
Out[5]//InputForm=
{Root[10 + #1 + 3*#1^2 + 7*#1^3 + #1^4 & , 1, 0], Root[10 + #1 + 3*#1^2
+ 7*#1^3 + #1^4 & , 2, 0]}
Finally I can get a form containing Radicals, executing the command:
In[100]:=
ToRadicals[%]//InputForm
Out[100]//InputForm=
{-7/4 - Sqrt[41/4 + (5481 - 27*Sqrt[39481])^(1/3)/3 + (203 +
Sqrt[39481])^(1/3)]/2 -
Sqrt[(246 - 4*(5481 - 27*Sqrt[39481])^(1/3) - 12*(203 +
Sqrt[39481])^(1/3) +
801/Sqrt[41/4 + (5481 - 27*Sqrt[39481])^(1/3)/3 + (203 +
Sqrt[39481])^(1/3)])/3]/4,
-7/4 - Sqrt[41/4 + (5481 - 27*Sqrt[39481])^(1/3)/3 + (203 +
Sqrt[39481])^(1/3)]/2 +
Sqrt[(246 - 4*(5481 - 27*Sqrt[39481])^(1/3) - 12*(203 +
Sqrt[39481])^(1/3) +
801/Sqrt[41/4 + (5481 - 27*Sqrt[39481])^(1/3)/3 + (203 +
Sqrt[39481])^(1/3)])/3]/4}
I hope this will be helpful for you.
Cheers,
Jim
Ο/Η akil έγραψε:
{-7., 2., 3.}
Bob Hanlon
ToRules did the trick.
I don't know why Reduce just does not include an link to the section where
they explain ToRules, because an example using Reduce is shown there, as i
saw after all the advice I got.
Akil
"akil" <ako...@wanadoo.nl> schreef in bericht
news:ebmtf5$6fb$1...@smc.vnet.net...
type1= answer == Real1 || answer == Real2;
type2= answer == Real3;
getReal=Cases[{#}, answer == y_ :> y, Infinity]&;
getReal[type1]
--> {Real1,Real2}
getReal[type2]
--> {Real3}
getReal[type2 || type1]
--> {Real3,Real1,Real2}
HTH,
Peter
In[]:= #[[2]]&/@Cases[Reduce[whatever...,x],x==b_,Infinity]
But to clarify your question it would be good to add an example...
lg cl
On Sun, 13 Aug 2006 05:52:24 -0400 (EDT)
"akil" <ako...@wanadoo.nl> wrote:
> After using reduce I get the following two types of answers:
>
> answer == Real1 || answer == Real2
> or
> answer == Real3
> , the type can change from one formula to another.
>
> I need the Reals, and put them all in a list. The problem is getting all
> the
> reals, without knowing which type I deal with, it should be able to be done
> fast.
>
> I tried making a list of the returned adres, and then using
> Cases[list, _Real, Infinity] and using Select[list,NumericQ] but both do
> not
> give me the answer I require.
>
> How can I get the answer I require e.g. something like {Real1,Real2,Real3}
>
>
>
-- Mag. Christoph Lhotka --
University of Vienna / Institute for Astronomy
fon. +43 (1) 4277 51841
mail. lho...@astro.univie.ac.at
In[1]:=
List@ToRules[a\[Equal]1]
Out[1]=
{{a\[Rule]1}}
In[2]:=
List@ToRules[a\[Equal]1||a\[Equal]2]
Out[2]=
{{a\[Rule]1},{a\[Rule]2}}
On 8/13/06, akil <ako...@wanadoo.nl> wrote:
> After using reduce I get the following two types of answers:
>
> answer == Real1 || answer == Real2
> or
> answer == Real3
> , the type can change from one formula to another.
>
> I need the Reals, and put them all in a list. The problem is getting all the
> reals, without knowing which type I deal with, it should be able to be done
> fast.
>
> I tried making a list of the returned adres, and then using
> Cases[list, _Real, Infinity] and using Select[list,NumericQ] but both do not
> give me the answer I require.
>
> How can I get the answer I require e.g. something like {Real1,Real2,Real3}
>
>
>
>
On 8/14/06, akil <ako...@wanadoo.nl> wrote:
> Thanks All,
>
> ToRules did the trick.
>
> I don't know why Reduce just does not include an link to the section where
> they explain ToRules, because an example using Reduce is shown there, as i
> saw after all the advice I got.
>
> Akil
>
> "akil" <ako...@wanadoo.nl> schreef in bericht
> news:ebmtf5$6fb$1...@smc.vnet.net...