[Date Index]
[Thread Index]
[Author Index]
Re: Re: Gradient Option in FindMinimum
*To*: mathgroup at smc.vnet.net
*Subject*: [mg13343] Re: [mg13265] Re: Gradient Option in FindMinimum
*From*: Carl Woll <carlw at fermi.phys.washington.edu>
*Date*: Mon, 20 Jul 1998 02:50:00 -0400
*Sender*: owner-wri-mathgroup at wolfram.com
Hi Robert,
I noticed your response to Chris' question, but it leaves me somewhat
confused. Consider the following:
f1=2 x;
f2={2 x};
FindMinimum[x^2, {x,1.}, Gradient->2 x] FindMinimum[x^2, {x,1.},
Gradient->{2 x}] FindMinimum[x^2, {x,1.}, Gradient->f1]
FindMinimum[x^2, {x,1.}, Gradient->f2] FindMinimum[x^2, {x,1.},
Gradient->{f1}]
fail, but instead, the only one that has an error is the one with f2,
which is essentially the one that gave Chris problems. All the others
return the same, correct, answer. So, the problem with f2 must be a
little more complicated then the HoldAll attribute of FindMinimum.
Perhaps you could explain what is going on here?
Thanks,
Carl Woll
Dept of Physics
U of Washington
On Fri, 17 Jul 1998, Robert Knapp wrote:
> 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: beginner's question -- syntax related?**
Next by Date:
**Re: Re: Derivatives D[ ] as Functions: Summary (LONGISH)**
Previous by thread:
**Re: Gradient Option in FindMinimum**
Next by thread:
**Re: Re: Gradient Option in FindMinimum**
| |