4
$\begingroup$

Today, while helping someone solve a problem, I encountered an issue with the Abs function in their expression. I needed to derive the Abs function and then plot it. The original image was a curve, but the plot ended up as a discontinuous straight line, which is obviously wrong. So, I started to check my code step by step and found the problem lies with the derivative of the Abs function.

Here I used the N function, but I didn't get a numerical solution. Then, in the suggestion bar below, Mathematica suggested I use FunctionExpand. I tried this function, and it indeed worked.

enter image description here

I'm not sure why this is the case and I'm hoping someone can help explain it to me.

$\endgroup$
3
  • 1
    $\begingroup$ This is a bug in FunctionExpand. According to the documentation to Abs "Abs is not a differentiable function". $\endgroup$
    – user64494
    Apr 9 at 15:33
  • $\begingroup$ I don't understand the explanation "Adding assumptions that the argument is real makes Abs differentiable" in the documentation. The correct formulation should be as "The restriction of Abs[z] on the real axis is a differentiable function of the real variable z, except z==0, and this function is denoted by RealAbs[z]". $\endgroup$
    – user64494
    Apr 9 at 15:54
  • $\begingroup$ Related: mathematica.stackexchange.com/q/8188/1871 $\endgroup$
    – xzczd
    Apr 14 at 11:37

2 Answers 2

2
$\begingroup$

As far as I understand the documentation to FunctionExpand, here

FunctionExpand[D[Abs[x], x], Assumptions -> x > 0]

1

is used for x == 0.9510565162951535.

$\endgroup$
4
$\begingroup$
$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global`*"]

As stated in the documentation, "Abs is a function of a complex variable and is therefore not differentiable." You must either use assumptions or use RealAbs. Then use PiecewiseExpand.

der[t_] = Derivative[1][RealAbs][Sin[2 Pi  t]] // PiecewiseExpand

(* Piecewise[{{-1, Sin[2*Pi*t] < 0}}, 1] *)

der[0.2]

(* 1 *)

Plot[{Abs[Sin[2 Pi  t]], der[t]}, {t, 0, 2}]

enter image description here

EDIT: Or using Assumptions and FullSimplify

FullSimplify[Abs'[Sin[2 Pi  t]], Assumptions -> t ∈ Reals]

(* Sign[Sin[2 π t]] *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.