Re: lists w/o double brackets

• To: mathgroup at smc.vnet.net
• Subject: [mg31446] Re: lists w/o double brackets
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Wed, 7 Nov 2001 05:29:04 -0500 (EST)
• References: <9s5jmh\$4lo\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Gavin,
Two suggestions ( both turn on changing a list List[x...], full form of
{x....}, into a sequence, Sequence[x...])
Note that f@@expr is short for Apply[f, expr].

initialvals = {{x, 1}, {y, 2}};

eqns = {x + y == 2, x - y == 3};

(FindRoot[eqns, ##1] & ) @@ initialvals

{x -> 2.5, y -> -0.5}

FindRoot[eqns, Evaluate[Sequence @@ initialvals]]

{x -> 2.5, y -> -0.5}

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Gavin K Brennen" <gbrennen at unm.edu> wrote in message
news:9s5jmh\$4lo\$1 at smc.vnet.net...
> Hello,
>
> I am using the function FindRoot with a large number of simultaneous
equations.
>
> FindRoot[eqs,initialvals]
>
> I have a function for generating the equations which works fine as a list
> input in FindRoot, however I am having difficulty creating a function for
> generating initialvals that will be accepted by FindRoot.  The problem
> seems to be that FindRoot demands a format
>
> FindRoot[{eq1,eq2,...,eqn},{var1,val1},{var2,val2},...,{varn,valn}]
>
> the variables and initial values of which must appear as a list without
> double brackets.  The function I have for generating the initial values
> always outputs the list as follows
>
>
> Input
> initialvals
> Output
> {{var1,val1},{var2,val2},...,{varn,valn}}.
>
> Note the double brackets which FindRoot will not accept.
> I have tried using
>
>   initialvals2=StringReplace[ToString[initialvals], {"{{" -> "{", "}}" ->
> "}"}]
>
> which eliminates the double brackets, however FindRoot will not accept
> stings as input for the variables and upon converting back to an
Expression
> using
>
> ToExpression[initialvals2]
>
> the double brackets return.
>
> Is there a solution to this without having to manually cut and paste the
> output of my expression for initialvals without the double brackets into
> FindRoot?
>
> Thanks much,
>
> Gavin
> gbrennen at unm.edu
>
>
>

```

• Prev by Date: Re: lists w/o double brackets
• Next by Date: RE: Re: Finding variables in a very long expression
• Previous by thread: Re: lists w/o double brackets
• Next by thread: ListContourPlot Color