Re: Output of "Solve" as a list
- To: mathgroup at smc.vnet.net
- Subject: [mg28618] Re: [mg28599] Output of "Solve" as a list
- From: BobHanlon at aol.com
- Date: Wed, 2 May 2001 03:37:09 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Solve does give a list; however, it is a list of replacement rules rather
than a list of values.
Solve[x^2 == 4, x]
{{x -> -2}, {x -> 2}}
To convert to a list of values
data = x /. Solve[x^2 == 4, x]
{-2, 2}
data^3
{-8, 8}
To restrict the results, use Select or Cases
data = Select[x /. Solve[x^2 == 4, x], #>= 0&]
{2}
data = Cases[x /. Solve[x^2 == 4, x], _?NonNegative]
{2}
Bob Hanlon
In a message dated 2001/5/1 12:41:40 AM, dkl2 at zahav.net.il writes:
>Asking for "Solve" command won't give a list , for example:
>
>In[23]:=
>data = Solve[x\^2 == 4, x]
>Out[23]=
>{{x -> -2}, {x -> 2}}
>
>But if I want to use the output , for example :
>
>In[24]:=
>data^3
>Out[24]=
>( ( x -> (-2) }^3, ( (x -> {2) }^3 } .
>
>the software dosen't consider x-> ... , as a number ,
>but literally as "x->..." , so when asking data^3 it gives
>(x->...)^3 .
>
>Can anyone help me ? , thank you .
>