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[1]:= sol = {{x -> 1, y -> 2}} Out[1]= {{x -> 1, y -> 2}} In[2]:= {x, y} /. sol[[1]] Out[2]= {1, 2} In[3]:= z = x^2 + Sqrt[x*y] /. sol[[1]] Out[3]= 1 + Sqrt[2] For more information, see http://reference.wolfram.com/mathematica/ref/ReplaceAll.html http://reference.wolfram.com/mathematica/tutorial/ApplyingTransformationRules.html Regards, -- Jean-Marc