开发者

Mathematica code: Derivative of Abs[x]

Note to closers : This is a question about a Programming language (Mathematica), and not about a discipline/science (mathematics).

Why is

N[D[Sin[x], x] /. x -> Pi/4]
(*
Out -> 0.707107
*)

but

N[D[Abs开发者_如何学Go[x], x] /. x -> Pi/4]
(*
Out -> Derivative[1][Abs][0.785398]
*)

?

And what is the better way to force a numerical result?


Abs[z] is not a holomorphic function, so its derivative is not well defined on the complex plane (the default domain that Mathematica works with). This is in contradistinction to, e.g., Sin[z], whose complex derivative (i.e., with respect to its argument) is always defined.

More simply put, Abs[z] depends on both z and z*, so should really be thought as a two argument function. Sin[z] only depends on z, so makes sense with a single argument.

As pointed out by Leonid, once you restrict the domain to the reals, then the derivative is well defined (except maybe at x=0, where they've taken the average of the left and right derivatives)

In[1]:= FullSimplify[Abs'[x],x \[Element] Reals]
Out[1]= Sign[x]

As pointed out by Szabolcs (in a comment), FunctionExpand will simplify the numerical expressions, but "Some transformations used by FunctionExpand are only generically valid".

ComplexExpand also gives numeric results, but I don't trust it. It seems to take the derivative assuming the Abs is in the real domain, then substitutes in the numeric/complex arguments. That said, if you know that everything you're doing is in the reals, then ComplexExpand is your friend.


I refer you to this thread as possibly relevant - this issue has been discussed before. To summarize my answer there, Abs is defined generally on complex numbers. Once you specify that your argument is real, it works:

 In[1]:= FullSimplify[Abs'[x], Assumptions -> {Element[x, Reals]}] 

 Out[1]= Sign[x] 


You can use FunctionExpand to force getting a number as a result even when you are using exact quantities:

Abs'[Pi/4] // FunctionExpand
Abs'[-1] // FunctionExpand

I do not know the reason for the following though:

In:= Abs'[0] // FunctionExpand
Out= 0
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜