       Re: Simple Q: How to give computed results from NSolve to a new

• To: mathgroup at smc.vnet.net
• Subject: [mg87273] Re: Simple Q: How to give computed results from NSolve to a new
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Sun, 6 Apr 2008 06:43:01 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <ft7gfo\$br6\$1@smc.vnet.net>

```loveinla at gmail.com wrote:

> I have solved a system of equations by NSolve. And for instance, it returns the results as
> Root={{x->1,y->2}}.
>
> And now I want to use the computed results, say x & y to define a new variable
> Z=x^2+sqrt(xy).
>
> How should I use computed x and y to define the new variable Z?

Assuming you use the correct syntax to define the variable z, you just
have to apply the transformation rules (i.e. "something" -> "something
else")via the replacement operator /. as in the following example:

In:= sol = {{x -> 1, y -> 2}}

Out= {{x -> 1, y -> 2}}

In:= {x, y} /. sol[]

Out= {1, 2}

In:= z = x^2 + Sqrt[x*y] /. sol[]

Out= 1 + Sqrt

For more information, see

http://reference.wolfram.com/mathematica/ref/ReplaceAll.html

http://reference.wolfram.com/mathematica/tutorial/ApplyingTransformationRules.html

Regards,
-- Jean-Marc

```

• Prev by Date: Re: Re: solving a system of polynomial equations
• Next by Date: Re: Inconsistent behavior?
• Previous by thread: Re: Simple Q: How to give computed results from NSolve to a new
• Next by thread: same input ... different results???