MathGroup Archive 2005

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

Search the Archive

Re: piecewise vs which

  • To: mathgroup at
  • Subject: [mg60118] Re: [mg60101] piecewise vs which
  • From: Curtis Osterhoudt <gardyloo at>
  • Date: Sat, 3 Sep 2005 02:06:06 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

Hi, Bradley,

   Some similar questions -- but with limits of +/- Infinity  -- have
been bantered about on this group recently regarding limits.

   The Piecewise function returns 0 as a default value when a domain
isn't given for an argument. I found this from the command ?Piecewise,
but it's also in the fuller Help Index documentation, of course. If you
make a larger "gap", say,

f[x_] := Piecewise[{{x^2, x < 2}, {3*x, x > 10}}]

then Piecewise will return 0 for values for 2<= x <= 10.

For the students' sake you might define f to return Null at
"unspecified" arguments, with

f[x_] := Piecewise[{{x^2, x < 2}, {3*x, x > 10}}, Null]

This should plot and behave more as you expect. Also, the Limit function
now works as you'd expect, including directed limits: try

 Limit[f[x], x -> 2, Direction -> 1]   


 Limit[f[x], x -> 2].

Curtis O.

Bradley Stoll wrote:

>Consider defining a function in Mathematica (v. 5.2) in two different
>ways:  f[x_]=Piecewise[{{x^2,x<2},{3x,x>2}}] and
>g[x_]=Which[x<2,x^2,x>2,3x].  Notice that 2 is not in the domain of
>either function.  However, if I ask for f[2], Mathematica returns 0 and if I ask
>for g[2] Mathematica (correctly) returns nothing.  Is this a bug with
>Mathematica (that Mathematica returns 0 for f[2]), since 2 is not in the domain?
>While I have eyes, there is another question regarding limits.  Is it
>the case that Limit[f[x],x->2] defaulted as
>Limit[f[x],x->2,Direction->-1] (a right hand limit)?  Both return 6 in
>the above example.  I'm using Mathematica in my calculus class and would
>like to explain why Mathematica does certain things.  It doesn't seem
>that it would've been too difficult to just have two subroutines (a
>right and left hand limit) to determine whether a 'full' limit actually

PGP Key ID: 0x235FDED1
Please avoid sending me Word or PowerPoint attachments.

  • Prev by Date: Re: Re: inconsistency with Inequality testing and Floor
  • Next by Date: Re: piecewise vs which
  • Previous by thread: Re: piecewise vs which
  • Next by thread: Re: piecewise vs which