Re: Simple Concept I can't figure out! Making rules?
- To: mathgroup at smc.vnet.net
- Subject: [mg38190] Re: Simple Concept I can't figure out! Making rules?
- From: atelesforos at hotmail.com (Orestis Vantzos)
- Date: Thu, 5 Dec 2002 03:29:23 -0500 (EST)
- References: <200211281907.OAA23937@smc.vnet.net> <asi0t3$eqb$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
The 'correct' way is to store the rule itself:
sol=Solve[2x==1,x]
To be honest, since Solve is designed to handle multiple solutions, if
you are certain you need only one use:
sol=Solve[2x==1,x]//First
Now sol looks like x->1/2
How do you use this?
Just let it Replace x in the expression you want:
x/.sol
--> 1/2
x^2 /. sol
--> 1/4
Sin[x Pi] /. sol
--> 1
etc.
It's much better than just keeping the value stored and then manually
replacing x in every expression.
Orestis
Vladimir Bondarenko <vvb at mail.strace.net> wrote in message news:<asi0t3$eqb$1 at smc.vnet.net>...
> snarten at runbox.com (Stan) wrote on Thursday, November 28, 2002, 3:07:35 PM :
>
> S> here is my problem:
>
> S> Lets say you solve an equation using "Solve"
>
> S> Solve[2x - 1 == 0, x] // N
>
> {{x ->> 0.5}}
>
> S> How would I then use the result of "Solve" (0.5) and assign it to a
> S> new variable, like "answer" for further calculations?
>
>
> Just use [[...]] (or its prefix equivalent, Part) to select a part of the
> output you want to use for your further calculations.
>
> In[1] := answer = (Solve[2x - 1 == 0, x] // N)[[1, 1, 2]];
>
> In[2] := answer^2
>
> Out[2] = 0.25
>
>
>
> Best wishes,
>
> Vladimir Bondarenko
> Mathematical and Production Director
> Symbolic Testing Group
>
> http://www.CAS-testing.org/ GEMM Project (95% ready)
>
> Email: vvb at mail.strace.net
> Voice: (380)-652-447325 Mon-Fri 6 a.m. - 3 p.m. GMT
> ICQ : 173050619
> Mail : 76 Zalesskaya Str, Simferopol, Crimea, Ukraine