If the curve is defined as c[t], interpolating 2D points, FindMinimum doesn’t work. If it is defined as {c1[t],c2[t]}, where c1 interpolates the x-values, and c2 interpolates the value, it works. Is there some reason I should expect this, from some (deeper than I understand) nature of Mathematica, or should we call this (gasp!) a bug?
I can’t say that i understand why it shouldn’t work in the original. But I guess
f[t_?NumberQ]
for the function to be minimized avoids all sorts of stuff I don’t understand. It just tells FindMinimum “Just do the numbers”. … and we both understand numbers in the same way.
Well, thanks for the reply. But why “it treats c[t] as a number,”? when it should know that c[t] is a 2-list, since it was generated that way. As I said, too deep for me. My conclusion: just make the argument of FindMinimum a function that only takes numerical arguments and returns a numerical result, and mysterious “treats as” questions go away…
I think (the Mathematica priests will say) that c is a function whose values are 2-lists. It is not two functions. As i say, this is too subtle for me …
I wouldn’t call myself a priest of Mathematica, and you surely have exposed a pitfall in the system, into which I could have fallen myself. I am just trying to explain the reasons behind the problem. Your symbolic expression c[t] has an InterpolatingFunction object as Head; it only becomes a List when t is a number. When faced with c[t]+{a,b}, the c[t] is not treated as a list. Yes, I suppose that Mathematica could be programmed to check if c[t]could become a list of length 2 when t is numeric, but this would imply messing with addition, and making it slower in many other circumstances (maybe, I am just guessing). So, until Wolfram changes the behaviour of Plus, the creator of a vector-valued InterpolatingFunction must take care of its creature. The same pitfall holds for other constructs, for example
a[t_] := Piecewise[{{{t, t}, t > 0}}, {0, 0}]
This is meant to be a vactor-valued function, but try what happens with a[t]+{1,2}.
Your solution to define f[t_?NumberQ] := dsq[c[t], q]is perfectly valid, because this way the expressions c[t]-q and c[t]+q will only be evaluated when t is a number, and there is no symbolic pre-processing. Another solution could be to restrict the definition of dst to explicit lists:
Update: Henrik’s suggestion to use Threaded is also a good solution. Perhaps contrary to its name, Threaded prevents the threading of Plus in such cases as Threaded[a] + {1, 2}, when a is not a list. Threaded was introduced in version 13.1 and is stille experimental.