MathGroup Archive 1999

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

Search the Archive

Re: Starting values with FindRoot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg20649] Re: [mg20620] Starting values with FindRoot
  • From: BobHanlon at aol.com
  • Date: Sun, 7 Nov 1999 02:09:54 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

Benoit,

eq = Table[z[i]^2 == 2  * i, {i, 2}];
x0 = Table[{z[i], i +  .5}, {i, 2}];

FindRoot[eq, Evaluate[Sequence @@ x0]]

{z[1] -> 1.4142135623746899, z[2] -> 2.0000000929222947}

Bob Hanlon

In a message dated 11/4/1999 7:18:45 AM, benoit at ecn.ulaval.ca writes:

>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?
>


  • Prev by Date: Problem with Solve[]
  • Next by Date: Re: Intersection and element counts
  • Previous by thread: Starting values with FindRoot
  • Next by thread: Re: Starting values with FindRoot