Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Gradient Option in FindMinimum

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13265] Re: Gradient Option in FindMinimum
  • From: Robert Knapp <rknapp>
  • Date: Fri, 17 Jul 1998 03:17:56 -0400
  • Organization: Wolfram Research, Inc.
  • References: <6od3be$hq8@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Chris Farr wrote:
> 
> Math Group:
> 
> Is the following a bug?
> 
> First, I set nameofgrad equal to 2*x.
> 
> In[32]:= nameofgrad = {2*x}
> Out[32]= {2 x}
> 
> Second, I show that if {2*x} is put directly into the FindMin. =
> expression everything works okay.
> 
> In[33]:= FindMinimum[x^2,{x,1.},Gradient->{2* x}] Out[33]= { 0.,{x
> -> 0.} }
> 
> Third, here is the bug (I think), when I put nameofgrad into the =
> FindMin. expression (which is just equal to {2*x}), I get an error =
> message!
> 
> In[34]:= FindMinimum[x^2,{x,1.},Gradient->nameofgrad]
> 
> FindMimimum::fmgl : Gradient {{2.}} is not a length 1 list of real =
> numbers at {x} = {1.}
> 
> Can anyone duplicate this on their machine?  Any ideas?
> 

This is quite reproducible since it is caused by the evaluation
semantics of FindMinimum, in particular that it has the HoldAll
attribute.  Thus, the arguments are passed to the function unevaluated,
so FindMinimum sees the gradient as just the symbol nameofgrad which is
noty a list.  Since it needs the gradient to be a list, it warps a list
around that, leading to your eventual problem.

This can easily be remedied by simply using

 FindMinimum[x^2,{x,1.},Evaluate[Gradient->nameofgrad]]

which forces the third argument to be evaluated.

Rob Knapp


  • Prev by Date: Re: Can it be done - easily?
  • Next by Date: Re: Can it be done - easily?
  • Previous by thread: Gradient Option in FindMinimum
  • Next by thread: Re: Re: Gradient Option in FindMinimum