RE: Re: Assigning solutions fou
- To: mathgroup at smc.vnet.net
- Subject: [mg9490] RE: [mg9450] Re: Assigning solutions fou
- From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
- Date: Sat, 8 Nov 1997 23:04:23 -0500
- Sender: owner-wri-mathgroup at wolfram.com
Hein Hundal replied to a question about how to convert a list of Rules from FindRoot to a list of numbers. Hein said: | | Try | | sols=FindRoot[{x == y, x + y == 2}, {x, 0}, {y, 0}] Set @@#& /@ sols | | Are you sure? It doesn't work for me unless I include a semi-colon as follows: In[1]:= sols=FindRoot[{x == y, x + y == 2}, {x, 0}, {y, 0}] ;Set @@#& /@ sols Out[1]= {1.,1.} I find this sort of code very cryptic, and I think it's a sure fire way to turn off beginners. Besides that it goes about the task in a round about way. Something like the following is more direct and more readable. In[2]:= solution=FindRoot[{x == y, x + y == 2}, {x, 0}, {y, 0}] Out[2]= {1.\[Rule]1.,1.\[Rule]1.} In[3]:= {x,y}/.solution Out[3]= {1.,1.} Note: I didn't put a semi-colon after FindRoot[.......] so a beginner will know what the next line is working on. Now if the user wanted to assign values to {x,y} they could use the following. In[4]:= {x,y}={x,y}/.solution Out[4]= {1.,1.} Ted Ersek ersek_ted%pax1a at mr.nawcad.navy.mil