MathGroup Archive 1999

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

Search the Archive

Re: Starting values with FindRoot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20664] Re: [mg20620] Starting values with FindRoot
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sun, 7 Nov 1999 02:10:02 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Benoit,

The function you need is Sequence. Check it out in Help. Sequence @@ x0 replaces the
list of starting approximations by a sequence of arguments.

f[x0]
f[{{z[1], 1.5}, {z[2], 2.5}}]

f[Sequence @@ x0]
f[{z[1], 1.5}, {z[2], 2.5}]

Since FindRoot has the attributes HoldAll, we have to Evaluate it in the statement.

FindRoot[eq, Evaluate[Sequence @@ x0]]
Out[4]=
{z[1] -> 1.41421, z[2] -> 2.}

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/

>
>I am fairly new to Mathematica. I have to solve numerically a large set
>of nonlinear equations. My question is: How can I set the starting
>values without having to explicitly name every variable? Here is an
>example of what I mean: Suppose I try to solve numerically the following
>two equations:
>eq = Table[z[i]\^2 == 2  i, {i, 2}]
>
>It would be nice if starting values could be set as a List. Example:
>
>x0 = Table[{z[i], i +  .5}, {i, 2}]
>
>and to solve the equations with the following statement:
>
>FindRoot[eq,x0]
>
>Unfortunetly, it does not work. Mathematica does not seem to accept
>starting values as lists. The problem appears to be the outer {}. In
>place of x0 above, Mathematica looks for something like
>{z[1],1.5},{z[2],2.5}, while x0={ {z[1],1.5},{z[2],2.5} }. There is an
>extra set of {}.
>
>I have found a solution by using a chain of  FullForm[], ToString[],
>StringDrop[] and ToExpression[]. Here is my solution:
>
>ToExpression[ToString[FindRoot] <> "[" <> ToString[FullForm[eq]] <> ","
><>
>    StringDrop[StringDrop[ToString[x0], 1], -1] <> "]"]
>
>Althought this works OK, it is nevertheless a very roundabout way of
>doing a simple thing. Anyone knows a more elegant way of doing this?
>
>
>
>Thanks in advance
>
>Benoit Carmichael
>Professeur
>Departement d'economique
>Pavillon J.-A. de Seve
>Cite Universitaire
>Ste-Foy (Quebec)
>Canada, G1K 7P4
>Tel.: (418) 656-2131 #5442
>
>



  • Prev by Date: Erasing a Plot?
  • Next by Date: Structural Mechanics Now Available
  • Previous by thread: Re: Starting values with FindRoot
  • Next by thread: Re: Starting values with FindRoot