MathGroup Archive 1999

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

Search the Archive

Re: Symbolic Derivative of Piecewise Contin Fcn

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15508] Re: Symbolic Derivative of Piecewise Contin Fcn
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Mon, 18 Jan 1999 23:47:11 -0500
  • References: <77v3jp$kn3@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Steve Sullivan wrote in message <77v3jp$kn3 at smc.vnet.net>...
>How can I get a symbolic derivative on a region of a piecewise
>continuous function using Mathematica? Two simple examples, extracted
>from long Modules are below.
>
>Alternatively, is there some magic functional M that, given a piecewise
>contin function, would return a piece of it?  For example, let:   f[x_]
>:= If[ x < 0, x^2, x^5] Is there a M such that:   M[ f, {x < 0}] would
>return:  x^2
>
>Many thanks for any help ...
>Steve
>
>
>The following examples of the failure of D[] are extracted from much
>more complicated functions.  They were run using Mathematica 3.0.
>
>htest[ uval_ ] := Module [
> {res},
> If[ uval < 0, res = uval^2, res = uval^5];
> res
>]
>
>D[ htest[ uval], uval]
>==> returns: 0
>
>
>
>tstb[ pow_Integer, uval_ ] := Module [
> {res}, (* local vars *)
> If[ pow == 0,
> If[ uval < 0, res = 0, res = uval^2],
> res = uval^5 * tstb[ pow-1, uval]
> ];
> res (* return *)
>]
>
>D[ tstb[  0, uval], uval]
>==> returns: 0
>
>D[ tstb[  1, uval], uval]
>==> returns: 5 res$4 uval^4         (?? what is res$4 ?)
>

Steve:

htest[ uval_ ] := If[ uval < 0, uval^2,  uval^5]

D[ htest[ uval], uval]

        If[uval < 0, 2*uval, 5*uval^4]


tstb[ pow_Integer, uval_ ] :=


        pow==0,
        If[ uval < 0, 0,uval^2],
        uval^5 * tstb[ pow-1, uval]
    ]

D[ tstb[ 0, uval], uval]

    If[uval<0,0,2 uval]

D[ tstb[ 1, uval], uval]

    uval^5*If[uval < 0, 0, 2*uval] +  5*uval^4*If[uval < 0, 0, uval^2]

Module is not necessary, Mathematica is functional.

res$4  is a local variable generated by Module


Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565




  • Prev by Date: Re: ContourPlot problem
  • Next by Date: Re: your post
  • Previous by thread: Symbolic Derivative of Piecewise Contin Fcn
  • Next by thread: Re: Symbolic Derivative of Piecewise Contin Fcn