Re: Simple Concept I can't figure out! Making rules?
- To: mathgroup at smc.vnet.net
- Subject: [mg38080] Re: Simple Concept I can't figure out! Making rules?
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Tue, 3 Dec 2002 04:28:51 -0500 (EST)
- References: <as5pgp$n96$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Stan, We have fullsolution = Solve[{x + y == 2, x^2 + y^2 == 10}, {x, y}] {{x -> -1, y -> 3}, {x -> 3, y -> -1}} The full solution contains two answers {x->-1,y->3} and {x->3,y->-1} This lets us state the full solution in a way that relates to the variables and also lets us do things like a x + b y /. solution {-a + 3 b, 3 a - b} Which gives the results of substituting using each of the two answers. With your example fullsolution = N[Solve[2 x - 1 == 0, x]] {{x -> 0.5}} We can get answer = x /. fullsolution[[1]] 0.5 answer 0.5 -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Stan" <snarten at runbox.com> wrote in message news:as5pgp$n96$1 at smc.vnet.net... > Even though it's frowned upon by the engineering college, i use > mathematica a lot of the stuff that would take pages of code in > another system. I have most basic functions and operations down, but I am > lacking one basic thing I need to do to be able to program more > problems successfully: > > here is my problem: > > Lets say you solve an equation using "Solve" > > Solve[2x - 1 == 0, x] // N > > {{x -> 0.5}} > > How would I then use the result of "Solve" (0.5) and assign it to a > new variable, like "answer" for further calculations? > > I think it has something to do with /. and -> rules of some sort, but > I can't get this simple concept to work! > > Thanks for the help. > > -Stan >