Re: Re: piecewise vs which

*To*: mathgroup at smc.vnet.net*Subject*: [mg60136] Re: [mg60128] Re: piecewise vs which*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>*Date*: Sun, 4 Sep 2005 03:01:59 -0400 (EDT)*References*: <df9437$620$1@smc.vnet.net> <200509030606.CAA19122@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

On 3 Sep 2005, at 15:06, Helen Read wrote: > 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 >> existed. >> > > Limit does indeed default to Direction->-1. Try, for example, > Limit[Abs[x]/x,x->0] > > I don't like this at all. For purposes of teaching calculus students, > where we are only concerned with real numbers and are not taking > limits > in the complex plane, I would like Limit to check from both > directions. > There are two basic reasons why Limit does not do that. First, variables in Mathematica are by default complex so a limit has not just two possible direction but infinitely many. And secondly, the correct way to compute limit is by using Series, that is Normal[Series[f[x],{x,a,1}]]/.x->a computes the limit of f[x] as x tends to a in the complex plane. There is, therefore, no good reason why Limit should duplicate a functionality that is already present. Finally, students learning calculus should first learn to compute limits by hand. By the time they can do it well enough so that it is safe to let them use Mathematica for this purpose they should also know why it is better to use Series. Andrzej Kozlowski

**References**:**Re: piecewise vs which***From:*Helen Read <hpr@together.net>

**Re: Re: piecewise vs which**

**Re: hints to speed up numerical integration?**

**Re: piecewise vs which**

**Re: piecewise vs which**