MathGroup Archive 1999

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

Search the Archive

Re: typing starting values in FindMinimum

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15492] Re: [mg15391] typing starting values in FindMinimum
  • From: BobHanlon at aol.com
  • Date: Mon, 18 Jan 1999 04:22:34 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 1/12/99 7:21:27 AM, amaydeu at nil.fut.es writes:

>Consider the use of FindMinimum when the function to be minimized
>depends on several variables
>
>In[1]:=
>j={{l2,l1,0},{l3,0,l1},{0,l3,l2}};
>e={0.56 -l1 l2,0.48 -l1 l3, 0.42 -l2 l3};
>FindMinimum[Apply[Plus,e^2],{l1,.5},{l2,.5},{l3,.5},Method->Newton,
>Gradient->j]
>
>Out[1]=
>{8.68919*^-23, {l1->.8, l2->.7, l3->.6}}
>
>Does anyone know to avoid having to type in all the variables names and
>starting values? 
>I have some problems with 100 variables!
>
>Of course I can construct
>
>In[3]:=
>theta={l1,l2,l3};
>start ={0.5,0.5,0.5};
>startval=Transpose[{theta,start}]
>
>Out[3]:=
>{{l1,0.5},{l2,0.5},{l3,0.5}}
>
>but that is not what FindMinimum is expecting.
>

Albert,

j={{l2,l1,0},{l3,0,l1},{0,l3,l2}};
e={0.56 -l1*l2,0.48 -l1*l3, 0.42 -l2*l3}; f = Apply[Plus,e^2];

To determine the variable names used in f

vars = Union[Cases[f, _Symbol, 4]]

{l1, l2, l3}

However, this requires all the variables to be at the same level.  If
this is not the case in the actual problem, 

f[[Sequence @@ #]]& /@ Position[f, _Symbol]

{Plus, Power, Plus, Times, l1, l2, Power, Plus, Times, 
  l1, l3, Power, Plus, Times, l2, l3}

To eliminate all of the names of the operators

vars = Union[Select[%,LowerCaseQ[StringTake[ToString[#], 1]]&]]

{l1, l2, l3}

This assumed that all the variables start with a lower case letter.

If all the starting values (estimates) are all the same

startValue = 0.5;
varStart = Transpose[{vars, 
			Table[startValue, {Length[vars]}]}];

Since you are using the Newton method, only one starting value is needed
for each variable and we have the required lists.  FindMinimum requires
that these be entered as a Sequence and the immediate application of
the Sequence must be forced (Evaluate):

FindMinimum[f, Evaluate[Sequence @@ varStart], 
	Method->Newton, Gradient->j]

{8.689196809893331*^-23, 
  {l1 -> 0.7999999999868436, l2 -> 0.7000000000066607, 
   l3 -> 0.6000000000051076}}

Which is the result that you sought.

Bob Hanlon


  • Prev by Date: HOW DO I........?
  • Next by Date: Re: Parts of a list
  • Previous by thread: Re: typing starting values in FindMinimum
  • Next by thread: Re: typing starting values in FindMinimum