Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Question about the derivative of Abs

236 views
Skip to first unread message

Sam Takoy

unread,
Jan 1, 2010, 5:35:48 AM1/1/10
to
Hi,

I kind of asked this question before, but in a more confusing context,
so now I would like to ask it by itself.

In the course of my computations, I get Abs' and Abs''. It is applied to
a positive number, so I think those values should be 1 and 0. However,
Mathematica fails to simplify it.

For example

In[34]:= Abs'[2.0]

Out[34]=
\!\(\*SuperscriptBox["Abs", "\[Prime]",
MultilineFunction->None]\)[2.]


These expressions really mess up my answers. How do I get Mathematica to
do these simplifications?

Thanks

Sam

dh

unread,
Jan 2, 2010, 5:03:10 AM1/2/10
to
Hi Sam,
mathematica does not know the derivative of Abs, but it is easy to add
a corresponding rule:

Abs'[x_?Positive] = 1
Abs''[x_?Positive] = 0

Daniel

Leonid Shifrin

unread,
Jan 2, 2010, 5:03:32 AM1/2/10
to
Sam,

The problem seems to be that 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]

In fact, it works also for specific integer arguments (although not
automatically)

In[2]:= FullSimplify[Abs'[2]]

Out[2]= 1

For a reason I don't understand, this does not work for specific real
arguments however:

In[3]:= FullSimplify[Abs'[2.0]]

Out[3]= (Abs^\[Prime])[2.]

I don't see a good reason for this and think that it should be fixed to also
simplify just like in the case of integers. On the other hand, the above
simplification with FullSimplify seems to be rather a point-like solution -
a result of some specific rule that has been added to the kernel. For
example, the second derivative would not simplify:

In[4]:= FullSimplify[Abs''[2]]

Out[4]= (Abs^\[Prime]\[Prime])[2]

So, coming back to your specific question, here is what I would do:

1. Define your own function <abs>, for example like this:

Clear[abs];
abs[x_]:=Piecewise[{{x,x>0},{-x,x<=0}}]

you may check that it works for derivatives without any extra simplification
effort:

In[5]:= abs'[1.5]

Out[5]= 1

In[6]:= abs''[1.5]

Out[6]= 0

2. Use replacement rules to replace Abs with <abs>, in places where you need
this:

In[7]:= Abs''[2.0]/.Abs-> abs

Out[7]= 0

Hope this helps.

Regards,
Leonid

Patrick Scheibe

unread,
Jan 2, 2010, 5:03:53 AM1/2/10
to
Hi,

PiecewiseExpand can do the trick. In your original post the Abs are
results from the Norm-function in ni[t_,a_,b_].
If you are sure the parameters there are Reals then the following is
Abs-free. To decide whether this is correct is your turn.

Clear["Global`*"]
Simp[a_, b_][expr_] :=
Simplify[expr,
Assumptions -> a > 0 && a < Pi/2 && b > 0 && b < Pi/2];
FSimp[a_, b_][expr_] :=
FullSimplify[expr,
Assumptions -> a > 0 && a < Pi/2 && b > 0 && b < Pi/2];

ComputeCs3D[zi_] := (ddt = Derivative[1, 0, 0];
dd1 = Derivative[0, 1, 0];
dd2 = Derivative[0, 0, 1];
vi = ddt[zi];
zialpha[t_, a_, b_] := {dd1[zi][t, a, b], dd2[zi][t, a, b]};
salphabeta =
Dot[zialpha[#1, #2, #3], Transpose[zialpha[#1, #2, #3]]] &;
sAlphaBeta = Inverse[salphabeta[#1, #2, #3]] &;
ni[t_, a_, b_] :=
Cross[zialpha[t, a, b][[1]], zialpha[t, a, b][[2]]]/
Norm[Cross[zialpha[t, a, b][[1]], zialpha[t, a, b][[2]]]] /.
Abs[val__] :> PiecewiseExpand[Abs[val], Reals];
c[t_, a_, b_] := Dot[ni[t, a, b], vi[t, a, b]] // FSimp[a, b];
c1[t_, a_, b_] :=
ddt[c][t, a, b] -
Dot[zialpha[t, a, b], vi[t, a, b],
sAlphaBeta[t, a, b], {dd1[c][t, a, b], dd2[c][t, a, b]}] //
Simp[a, b];
c2[t_, a_, b_] :=
ddt[c1][t, a, b] -
Dot[zialpha[t, a, b], vi[t, a, b],
sAlphaBeta[t, a, b], {dd1[c1][t, a, b], dd2[c1][t, a, b]}] //
Simp[a, b];
{c[#1, #2, #3], c1[#1, #2, #3], c2[#1, #2, #3]} &)
zi[t_, theta_, phi_] := {(1 + \[Epsilon] t)*Sin[theta] Cos[phi],
Sin[theta] Sin[phi], Cos[theta]};
ComputeCs3D[zi][0, \[Theta], \[Phi]] //
FSimp[\[Theta], \[Phi]] // MatrixForm

Cheers
Patrick

Bob Hanlon

unread,
Jan 2, 2010, 5:07:32 AM1/2/10
to

sub = {
Abs'[x_?NumericQ /; x != 0] -> Sign[x],
Abs''[x_?NumericQ /; x != 0] -> 0};

Abs'[2.0] + Abs''[2.0] /. sub

1


Bob Hanlon

---- Sam Takoy <samt...@yahoo.com> wrote:

=============

David W. Cantrell

unread,
Jan 2, 2010, 5:08:16 AM1/2/10
to

I don't know why you're getting Abs' and Abs'' in your answers, but perhaps
it's just because you have asked for derivatives of expressions involving
Abs itself. If that is the case, then you might consider avoiding Abs in
your input by instead using Sqrt[x^2] when x is real.

In[1]:= D[Sqrt[x^2], x]

Out[1]= x/Sqrt[x^2]

In[2]:= D[%, x]

Out[2]= -(x^2/(x^2)^(3/2)) + 1/Sqrt[x^2]

In[3]:= Simplify[{%%, %}, x > 0]

Out[3]= {1, 0}

David

David Bailey

unread,
Jan 4, 2010, 5:59:40 AM1/4/10
to
You could just clean up the answer by applying a suitable transformation:

expr /. {Abs'[y_]->1,Abs''[y_]->0}


David Bailey
http://www.dbaileyconsultancy.co.uk

0 new messages