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