Re: Summary: Which[] as Textbook Input, Plot[] Questions
- To: mathgroup at smc.vnet.net
- Subject: [mg54067] Re: [mg54037] Summary: Which[] as Textbook Input, Plot[] Questions
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Wed, 9 Feb 2005 09:27:50 -0500 (EST)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- References: <200502081031.FAA17755@smc.vnet.net>
- Reply-to: murray at math.umass.edu
- Sender: owner-wri-mathgroup at wolfram.com
You would like Mathematica 5.1, which introduces the new function Piecewise. You could enter your function like this: f[x_] := Piecewise[{{Sin[x]/x, x != 0}, {1, x == 0}}] Then the result of evaluating f[x] would be a display of exactly the kind you want, with the large left brace (albeit no commas). And then you could plot as usual: Plot[f[x], {x, -Pi, Pi}] Time to upgrade! By the way, it's unclear why you expressed your piecewise definition with three clauses, instead of just two: Which[x != 0, Sin[x]/x, x == 0, 1] Matt wrote: > Hello, > I apologize if the answer to this is somewhere glaringly obvious in > the documentation, however, after at least 4 hours pawing through both > the hardcover Mathematica 4.0 book by Wolfram and the in-program > Mathematica 4.1 documentation, I cannot find how I would annotate a > function that takes on different values based upon different domains. > To wit, something like: > > Clear[f]; > f[x_] := Which[x < 0, Sin[x]/x, x == 0, 1, x > 0, Sin[x]/x]; > Plot[f[x], {x, -pi, pi}, AxesLabel -> {"x", "f[x]"}; > > The 'Which' function is great for actually evaluating something, but I > was looking for something along the lines of traditional mathematical > notation (such as one would write on a chalkboard or on a sheet of > paper), where a large left-bracket would be used and the various > definitions of the function for the various ranges would be > 'constrained' by the bracket. > > I'll try to illustrate what I mean, where the '|'s that I will use > should be interpreted as a single, large left-bracket: > > | Sin(x)/x, x < 0 > f(x) = | 1, x = 0 > | Sin(x)/x, x > 0 > > Is there a way to do what I'm asking in Mathematica 4.1 (or even > above)? -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
- References:
- Summary: Which[] as Textbook Input, Plot[] Questions
- From: "Matt" <anonmous69@netscape.net>
- Summary: Which[] as Textbook Input, Plot[] Questions