Starting values with FindRoot
- To: mathgroup at smc.vnet.net
- Subject: [mg20620] Starting values with FindRoot
- From: Benoit Carmichael <benoit at ecn.ulaval.ca>
- Date: Thu, 4 Nov 1999 02:13:33 -0500
- Sender: owner-wri-mathgroup at wolfram.com
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