Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: here's one driving me mad!

  • To: mathgroup at
  • Subject: [mg44816] Re: here's one driving me mad!
  • From: "Peltio" <peltio at>
  • Date: Thu, 27 Nov 2003 11:39:16 -0500 (EST)
  • References: <bpuqlc$o6f$>
  • Reply-to: "Peltio" <peltioNOSP at>
  • Sender: owner-wri-mathgroup at

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}

You can also suppress the sd-> bit with a rule Rule[_, v_] -> v

    {sd->10} /. Rule[_,v_]->v

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
    (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
    or one solution in multiple variables
    - and a list of lists when there are multiple solutions in multiple

Help yourself!

invalid address in reply-to. Crafty demunging required to mail me.

  • Prev by Date: Re: here's one driving me mad!
  • Next by Date: RE: How to use Rules from Solve and FindRoot
  • Previous by thread: Re: here's one driving me mad!
  • Next by thread: change of a coefficient in a polynomial