If you have two variables x
and y
, with y = 1 - x
, then you really have a problem in just one variable x
. Noting that, you can reparametrise your function to be
1 - 2 * x + x^2 - 2 * (1 - x) + 2 * x * (1 - x) + (1 - x)^2
and going through the algebra shows that this is constant as a function of x
. Thus any value of x
in (0, 1) is a solution, and which one your algorithm converges to will basically be random: based on numerical roundoff and your choice of starting point.
The fact that gosolnp
's returned value is zero to within the limits of numerical precision should have been a tipoff, or even just plotting the curve.