MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Abs derivative (continued) (was Re: ? ? ? ! ?)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg8311] Re: Abs derivative (continued) (was Re: [mg8223] ? ? ? ! ?)
  • From: Olivier Gerard <jacquesg at pratique.fr>
  • Date: Sun, 24 Aug 1997 13:24:28 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

> Original message
> 
> > Can anyone explain what v3.0 of Mathematica thinks it's doing when it
> > executes
> > 
> >      Plot[Abs'[x], {x, -3/10, 3/10}]
> > 
> > ???
> > 
> > Note the prime:  The first argument of Plot was Abs'[x], not Abs[x].
> > 
> > The strange behavior I see appears both on a PowerMac 7200/120 running
> > Mac OS 7.5.3 and on a Wintel box running Windoze 95, so I presume that 
> > it isn't platform dependent--or at least, not fully so.
> > 
> > --Lou Talman
> 

Continuing on this subject (please see previous answer),

Ok for derivation, it seems ok.
What about Integration ?

Plotting  Integrate[Abs[t], {t,0,x}] gives correct result
but this is because Integrate succeeds in giving a symbolic result:

1/2 x Sqrt[ Re[x]^2 + Im[x]^2]

Of course, for real x, this is equivalent  to 1/2 x Abs[x]
but it gives us a good way to enhance the solution I gave
for implementing a correct Abs derivative.

Let's ask Mma to plot the derivative of the Abs formula:

 Plot[Sqrt[ Re[#]^2 + Im[#]^2]&'[x], {x, -3/10, 3/10}]

It gives us a splendid graph of the Sign function.
Why does it seems to works when Abs'[x] gives spurious results ?

I suppose it is because the derivative of the Real+Imag formula,

Im'[x] Im[x]   +   Re'[x] Re[x]
-------------------------------
   Sqrt[ Im[x]^2 + Re[x]^2 ]

involves only derivatives of Im and Re. They are certainly
calculated by the same algorithm than the one used for
Abs'[x] but as they are constant and do not change sign at 0 when going on 
the real line, the error introduced by the algorithm
is a lot less than in the plot that was the subject of
Lou's message, as shown for instance by

Plot[ Re'[x]-1, {x,-1,1}]

where the irregularities are of the order of $MachinePrecision.
Besides, these derivatives are on the second order compared to
Abs, so the adaptation mechanism of Plot can enter in function.

So it would be perhaps a good idea to replace the q&d solution
of my previous post by:

Unprotect[Abs];
Derivative[1][Abs] ^:=
    (Re'[#] Re[#] + Im'[#] Im[#]])/Sqrt[Re[#]^2 + Im[#]^2] & ;
Protect[Abs];



It has the advantage of giving coherent results in some
Complex Number cases while still being not completely rigorous.


Olivier Gerard







  • Prev by Date: Re: Extracting the domain of a function, dynamic programming
  • Next by Date: Re: L'Hopital's rule contradiction --- what am I messing up?
  • Previous by thread: NonlinearFit and NonlinearRegress
  • Next by thread: Turning Off FractionBox[ ] Globally?