Re: Extracting just the value of the variable from the result of Solve/NDSolve

*To*: mathgroup at smc.vnet.net*Subject*: [mg62838] Re: [mg62803] Extracting just the value of the variable from the result of Solve/NDSolve*From*: Renan <renan.birck at Gmail.com>*Date*: Tue, 6 Dec 2005 00:43:06 -0500 (EST)*References*: <dmpa43$hl7$1@smc.vnet.net> <200512032352.SAA15963@smc.vnet.net> <200512051841.NAA21150@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

On 12/5/05, Pradeep Suresh <pradeep at purdue.edu> wrote: > Hi all, > i am facing a peculiar problem with the curly brackets of the output of > Solve and NDsolve commands....the result of Solve/NSolve/DSolve/NDSolve > all are in the form of {{y->a}} format and at best by doing a y/.soln, i > can get it to {a}, but for my purposes of passing this result to > JAVA(using J/Link), i need the value of the variable as just 'a' and not > '{a}'(i hope i am making myself clear). > E.g. > eqn={F==2*T}; > T = 300; > sol = Solve[eqn, F] > F /. sol > > gives me {600}, as i said earlier i need the answer 600(which is > different in datatype compared to {600} even though for all practical > purposes {600} is the same as 600). When i use J/link to extract value, > the {600} is not considered an integer/string/double/function,...so i > cannnot use getInteger,getString etc. > Can someone plz suggest a solution this problem, however triveal as it > may sound, it is an important problem in using J/Link to talk with > Mathematica. This works in the Mathematica front-end, don't know about J/Link: eqn={F==2*T}; T = 300; sol = Solve[eqn, F] F /. sol[[1]] In[1]:= eqn = {F==2*T}; In[2]:= T=300; In[3]:= sol = Solve[eqn,F] Out[3]= {{F -> 600}} In[4]:= F/.sol[[1]] Out[4]= 600 Obviously, this technique blows up if there are multiple solutions to the equation. -- Thanks/obrigado, Renan "Wishmaster" Birck - Canoas, Rio Grande do Sul, Brasil MSN: wizard_of_yendor at hotmail.com Orkut: http://www.orkut.com/Profile.aspx?uid=2202360379963855296

**References**:**Extracting just the value of the variable from the result of Solve/NDSolve***From:*Pradeep Suresh <pradeep@purdue.edu>