Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #8449 > unrolled thread

Baffled by FindMinimum

Started bySam Takoy <sam.takoy@yahoo.com>
First post2012-02-10 10:57 +0000
Last post2012-02-11 20:49 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Baffled by FindMinimum Sam Takoy <sam.takoy@yahoo.com> - 2012-02-10 10:57 +0000
    Re: Baffled by FindMinimum David Skulsky <edskulsky@gmail.com> - 2012-02-11 20:49 +0000

#8449 — Baffled by FindMinimum

FromSam Takoy <sam.takoy@yahoo.com>
Date2012-02-10 10:57 +0000
SubjectBaffled by FindMinimum
Message-ID<jh2t6j$o9$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#8471

FromDavid Skulsky <edskulsky@gmail.com>
Date2012-02-11 20:49 +0000
Message-ID<jh6k9e$js3$1@smc.vnet.net>
In reply to#8449
According to the documentation, "The functions FindMinimum, FindMaximum, and FindRoot have the HoldAll attribute and so have special semantics for evaluation of their arguments. First, the variables are determined from the second argument, then they are localized. Next, the function is evaluated symbolically, then processed into an efficient form for numerical evaluation. Finally, during the execution of the command, the function is repeatedly evaluated with different numerical values..."

What you're seeing, I believe, is the symbolic evaluation step.

David

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web