I think that FindMinimum
does not accept symbolic matrix variables. Also, DistanceMatrix
must be given an explicit DistanceFunction
when the data are mixed numerical-symbolic, otherwise we get unexpected results:
DistanceMatrix[{{x}}, {{0}}]
{{1}}
This seems to give an answer:
Xrs1 = RandomReal[{0, 1}, {10, 3}];
Xrs2 = RandomReal[{0, 1}, {40, 3}];
Xdr2 = RandomReal[{-5, 5}, {40, 2}];
d = DistanceMatrix[Xrs1, Xrs2];
dr[Xdr1_] :=
DistanceMatrix[Xdr1, Xdr2,
DistanceFunction -> EuclideanDistance] /. Abs -> Identity;
f[Xdr1_] := Total[(dr[Xdr1] - d)^2, 2];
FindMinimum[f[Array[Xdr1, {10, 2}]],
Flatten[Table[{Xdr1[i, j], 0}, {i, 10}, {j, 2}], 1] // N]
I was forced to append an N
because of this further strange behaviour of DistanceMatrix
:
In[137]:= DistanceMatrix[{{x[1]}}, {0.},
DistanceFunction -> EuclideanDistance]
Out[137]= {{Abs[0. + x[1.]]}}
whereby x[1]
in input becomes x[1.]
on output.