Re: Symbolic Derivative of Piecewise Contin Fcn
- To: mathgroup at smc.vnet.net
- Subject: [mg15553] Re: Symbolic Derivative of Piecewise Contin Fcn
- From: "Atul Sharma" <mdsa at musica.mcgill.ca>
- Date: Tue, 26 Jan 1999 13:44:36 -0500 (EST)
- Organization: McGill University Computing Centre
- References: <77v3jp$kn3@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
The easiest way to set up the piecewise continuous function is to use the Which[ ] construct in your function definition. i.e. htest[uval_] := Which[uval < 0, uval^2, uval >=0, uval^5] In[63]:= D[htest[uval],uval] Out[63]= Which[uval < 0, 2 uval, uval >= 0, 5 uval^4] res$4 is a consequence of the scope rules within the module you set up, with the suffix $4 used to keep the variable distinct from the global variable of the same name. See section 2.6.3 in the Mathematica book re: variable names within modules: In[1]:= Module[{t}, Print[t]] Out[1]: = t$1 A. Sharma -------------------------------------------------------------------------- Atul Sharma MD, FRCP(C) Pediatric Nephrologist, McGill University/Montreal Children's Hospital 2300 Tupper, Montreal, QC, Canada H3H 1P3 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 ?) > > >