RE : How to extract a solution from Mathematica's answer to "Solve"
- To: mathgroup at smc.vnet.net
- Subject: [mg49381] RE : [mg49363] How to extract a solution from Mathematica's answer to "Solve"
- From: "Florian Jaccard" <florian.jaccard at eiaj.ch>
- Date: Sat, 17 Jul 2004 06:38:45 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
You should write MySolution = x/.%[[1]] But you can do it better : You can automatically obtain the assignments x1=first solution, x2=second solution, etc. , without knowing in advance how many solutions you have : In[1]:= solu = x /. Solve[(x-1)(x^2-5x+6) == 0, x]; In[2]:= Do[Evaluate[ToExpression[StringJoin["x", ToString[i]]]] = Evaluate[solu[[i]]], {i, Length[solu]}] In[3]:= x1 Out[3]= 1 In[4]:= x2 Out[4]= 2 In[5]:= x3 Out[5]= 3 regards F.Jaccard -----Message d'origine----- De : Rainer [mailto:wilhelm.rainer at gmx.net] Envoyé : vendredi, 16. juillet 2004 12:07 À : mathgroup at smc.vnet.net Objet : [mg49363] How to extract a solution from Mathematica's answer to "Solve" I have a question concerning the Solve command. Assume I have solved an equation using Solve. Mathematica returns the solutions in the following form (example for 2 solutions): {{x->-2}, {x->2}} Now, assume I wish always to pick the first of these two solutions and store it in a variable (to be able to continue working with it in the Notebook). Is there a command to "extract" the second solution and to store it in a variable. Since the response is in a form of a matrix {{...},{...}}, I have tried things like MySolution = %[[1]], but it always fails. I appreciate any helpful commands! Thanks Rainer