Why is the Out[74]
not {1 - a, {x -> -1}}
?
Maximize[{Sqrt[x^2] - a, -1 <= x <= 1}, x]
{1 - a, {x -> -1}}
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI suspect the reason this fails is because Mathematica does not know the derivative of Abs[x]
. The reason behind this is Abs[x]
is nowhere differentiable in the complex plane and Derivative
and D
take complex derivatives.
In Wolfram Alpha, we had to handle Abs
ourselves assuming real variables since most people would want that. If you run WolframAlpha["derivative of Abs[x]"]
, you'll see the step-by-step solution specifies x is a real variable.
Since Derivative
is not a protected symbol, we can add custom SubValues
:
Derivative[1][Abs] = Sign;
Derivative[2][Abs] = Derivative[1][Sign] = DiracDelta;
Now Mathematica knows the (real) derivatives of these functions:
D[Abs[x], x]
(* Sign[x] *)
D[Abs[x], {x, 2}]
(* DiracDelta[x] *)
D[Sign[x], x]
(* DiracDelta[x] *)
Unfortunately this does not fix your Maximize
issue:
Maximize[{Abs[x] - a, -1 <= x <= 1}, x]
(* Maximize[{-a + Abs[x], -1 <= x <= 1}, x] *)
Maximize[{(Abs[x] - a), -1 <= x <= 1}, {x, a}]
and see what you get. It is not a but. $\endgroup$1 - a
? It's not clear to me why MMA would return a symbolic maximum in the other instances and not here. $\endgroup$