MathGroup Archive 2012

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

Search the Archive

Baffled by FindMinimum

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124875] Baffled by FindMinimum
  • From: Sam Takoy <sam.takoy at yahoo.com>
  • Date: Fri, 10 Feb 2012 05:55:00 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Hi,

Please take a look at this simple code.

ObjectiveFunction[p_] := Module[{},
  Print["Why is this p: ", p];
  (p[[3]] - 1)^2 + Norm[p]]
p0 = {1, 2, 2, 1, 2};
FindMinimum[ObjectiveFunction[xx], {xx, {1, 2, 3, 2, 1, 2}}]

If you run it, you will find that ObjectiveFunction is called with the
argument "xx" rather than the numerical vector. How come?
Also, judging by the lack of the Print statement firing,
ObjectiveFunction is not called again. Yet, it eventually (after
complaining of understandable errors) produces the correct answer.
What's going on here? I would expect if to be called repeated in the
course of numerical minimization. I'm completely baffled by what's
going on here.

Here's the output:

During evaluation of In[377]:= Why is this p: xx

During evaluation of In[377]:= Part::partd: Part specification xx[[3]]
is longer than depth of object. >>

During evaluation of In[377]:= Part::partd: Part specification xx[[3]]
is longer than depth of object. >>

Out[380]= {0.75, {xx -> {-5.48284*10^-9, -7.29576*10^-9,
    0.5, -7.02789*10^-9, -5.48284*10^-9, -7.02789*10^-9}}}

Many thanks in advance,

Sam



  • Prev by Date: Re: How to call 'Clear' from within a function?
  • Next by Date: Re: How to call 'Clear' from within a function?
  • Previous by thread: Re: MenuCommand Events
  • Next by thread: Re: Baffled by FindMinimum