Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using answer form reduce

2 views
Skip to first unread message

akil

unread,
Aug 13, 2006, 6:04:21 AM8/13/06
to
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}

Jean-Marc Gulliet

unread,
Aug 14, 2006, 6:47:26 AM8/14/06
to

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

dimm...@yahoo.com

unread,
Aug 14, 2006, 6:48:27 AM8/14/06
to
Hi, akil,

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 έγραψε:

Bob Hanlon

unread,
Aug 14, 2006, 6:49:28 AM8/14/06
to
x /. {Reduce[(x - 3.) (x - 2.) (x + 7.) == 0, x] // ToRules}

{-7., 2., 3.}


Bob Hanlon

akil

unread,
Aug 14, 2006, 6:50:28 AM8/14/06
to
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...

Peter Pein

unread,
Aug 14, 2006, 7:03:35 AM8/14/06
to
akil schrieb:
Try pattern matching:


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

Christoph Lhotka

unread,
Aug 14, 2006, 7:04:36 AM8/14/06
to
If I understand well, this will work

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

Chris Chiasson

unread,
Aug 14, 2006, 7:06:37 AM8/14/06
to
look up ToRules in the help

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}
>
>
>
>


--
http://chris.chiasson.name/

Chris Chiasson

unread,
Aug 16, 2006, 4:02:36 AM8/16/06
to
The Mathematica system is so large - I am sure they have to be very vigilant
to maintain their current level of cohesiveness and cross-referencing.
If you send an email to technical support about it, you can probably
persuade them to add a cross reference to ToRules to make things
better for future users.

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...


--
http://chris.chiasson.name/

0 new messages