Edit, taking advantage of improvements to the code in the question and using PiecewiseExpand
in the answer.
The quantity to be minimized, c[b1, b2, f, uConstrained, v, p, u]
, contains two distinct Piecewise
functions, one with three regions in {x0, b21, b22, b1, b2}
space, and the other with five regions. ({w1, w2}
do not appear in the range definitions.) It can be converted into a single Piecewise
function of ten expressions and regions, to each of which ArgMin
can be applied in turn. Then, finding the minimum of the ten minimums would, in principle, give the desired result.
onepw = PiecewiseExpand[c[b1, b2, f, uConstrained, v, p, u]] // FullSimplify
(* Piecewise[
{{1/2 (b1^2 + b2^2 + b21^2 + b22^2) - (b1 + b21) w1 + w1^2 - (b2 + b22) w2 + w2^2,
-2 < b1 - b2 + b21 - b22 <= 2 && -2 < b1 + b21 - 2 x0 <= 2},
{1/4 ((b1 - b21)^2 + (b2 - b22)^2 + (b1 + b21 - 2 w1)^2 + (b1 + b21 - 2(1 + w2))^2),
-2 < b1 + b21 - 2 x0 <= 2 && ((2 + b1 + b21 > b2 + b22 && 4 + b2 + b22 < 2 x0) ||
b1 + b21 > 2 + b2 + b22)},
{1/4 ((b1 - b21)^2 + (b2 - b22)^2 + (b1 + b21 - 2 w1)^2 + (2 + b1 + b21 - 2 w2)^2),
2 + b1 + b21 <= b2 + b22 && -2 < b1 + b21 - 2 x0 <= 2},
{1/4 ((b1 - b21)^2 + (b2 - b22)^2 + (b2 + b22 - 2 w2)^2 + 4 (1 - w1 + x0)^2),
b1 + b21 > 2 + 2 x0 && 0 < b2 + b22 - 2 x0 <= 4},
{1/4 (b1 - b21)^2 + 1/4 (b2 - b22)^2 + (w2 - x0)^2 + (1 - w1 + x0)^2,
b1 + b21 > 2 + 2 x0 && b2 + b22 <= 2 x0},
{1/4 (b1 - b21)^2 + 1/4 (b2 - b22)^2 + (1 - w1 + x0)^2 + (2 - w2 + x0)^2,
b1 + b21 > 2 + 2 x0 && b2 + b22 > 4 + 2 x0},
{1/4 ((b1 - b21)^2 + (b2 - b22)^2 + (b2 + b22 - 2 w2)^2 + 4 (1 + w1 - x0)^2),
(-4 < b2 + b22 - 2 x0 <= 0 && 2 + b1 + b21 <= 2 x0) || (0 < b2 + b22 - 2 x0 <= 4 &&
b1 + b21 > 2 + 2 x0) || (-2 < b1 + b21 - 2 x0 <= 2 &&
-2 < b1 - b2 + b21 - b22 <= 2)},
{1/4 (b1 - b21)^2 + 1/4 (b2 - b22)^2 + (1 + w1 - x0)^2 + (w2 - x0)^2,
(-2 < b1 + b21 - 2 x0 <= 2 && 2 + b1 + b21 <= b2 + b22) || (b1 + b21 > 2 + 2 x0 &&
b2 + b22 <= 2 x0) || (2 + b1 + b21 <= 2 x0 && b2 + b22 > 2 x0)},
{1/4 (b1 - b21)^2 + 1/4 (b2 - b22)^2 + (1 + w1 - x0)^2 + (2 + w2 - x0)^2,
(-2 < b1 + b21 - 2 x0 <= 2 && ((2 + b1 + b21 > b2 + b22 && 4 + b2 + b22 < 2 x0) ||
b1 + b21 > 2 + b2 + b22)) || (2 + b1 + b21 <= 2 x0 && 4 + b2 + b22 <= 2 x0) ||
(b1 + b21 > 2 + 2 x0 && b2 + b22 <= 2 x0)}},
1/4 ((b1 - b21)^2 + (b2 - b22)^2 + (b2 + b22 - 2 (2 + w2))^2 + 4 (1 + w1 - x0)^2)] *)
Unfortunately, minimizing the first of these ten expressions,
ArgMin[onepw[[1, 1]], {b1, b2}]
produces a Piecewise
answer with a LeafCount
of 830699
(in about 15 minutes), and Simplify
runs for hours (twenty-one before I terminated that computation) without returning a result. Presumably, minimizing the other nine expressions produces similarly enormous results. The reason for the enormous results returned by ArgMin
is that the regions over which any of the ten expressions is valid are complex shapes in the five-dimensional space of parameters and solutions, and those shapes change with the values of the parameters. So, there are an enormous number of case to be considered.
A more practical approach is to define the function,
sol[x0t_, w1t_, w2t_, b21t_, b22t_] :=
ArgMin[Simplify[c[b1, b2, f, uConstrained, v, p, u],
x0 == x0t && w1 == w1t && w2 == w2t && b21 == b21t && b22 == b22t],
{b1, b2}, Reals]
which usually can produce the answer for a given set of parameters in several seconds. For instance,
sol[5/2, E, Pi, -7, 1.11]
(* {-7., 3.14159} *)
or
sol[19, 70, -71, 86, 19]
(* {86, 19} *)
Interestingly,
Count[Table[param = RandomInteger[{-300, 300}, 5];
param[[4 ;; 5]] == sol @@ param, 100], True]
suggests that {b1, b2} == {b21, b22}
is the answer roughly 90% of the time.
c[...]
local variablesx0, b21, b22, w1
are undefined $\endgroup$ – ulvi Apr 6 '18 at 23:07$Assumptions
) in the session don't allow Mathematica to find the result. Often an unevaluated result can be still useful later if further information is provided later on and the returned, unevaluated result is re-evaluated with it. $\endgroup$ – kirma Apr 7 '18 at 4:05