Re: here's one driving me mad!

*To*: mathgroup at smc.vnet.net*Subject*: [mg44779] Re: here's one driving me mad!*From*: "Peltio" <peltio at twilight.zone>*Date*: Thu, 27 Nov 2003 11:38:05 -0500 (EST)*References*: <bpuqlc$o6f$1@smc.vnet.net>*Reply-to*: "Peltio" <peltioNOSP at Miname.com.invalid>*Sender*: owner-wri-mathgroup at wolfram.com

Glenn Roberts wrote >i have used the FindRoot function and it returns an output: >{sd -> 10} say >how do i get the output to return it without the sd -> bit ? The most obvious answer is : apply the rule sd /. {sd->10} 10 You can also suppress the sd-> bit with a rule Rule[_, v_] -> v {sd->10} /. Rule[_,v_]->v {10} A more general approach could be the following procedure that uses Dimensions to understand how many solutions and how many variables are passed to it: toValues[li_] := Module[ {newli, vars, sols}, sols = First[Dimensions[li]]; vars = Last[Dimensions[li]]; newli = li /. Rule[_, v_] -> v; If[vars == 1, newli = Flatten[newli]]; If[sols == 1, First[newli], newli] ] This procedure gives - the value if there is only one solution in one variable {{x->10}}//toValues 10 {x->10}//toValues 10 (as an aside: the latter works because First and Last give the same single value (1) to sols and vars) - a list of values if there are multiple solution in one variable {{x->2},{x->-2}}//toValues {2,-2} or one solution in multiple variables {{x->1,y->2}}//toValues {1,2} - and a list of lists when there are multiple solutions in multiple variables {{x->1,y->2},{x->0,y->-1}}//toValues {{1,2},{0,-1}} Help yourself! cheers, Peltio invalid address in reply-to. Crafty demunging required to mail me.