Re: Summary: Whichas Textbook Input, PlotQuestions

*To*: mathgroup at smc.vnet.net*Subject*: [mg54071] Re: Summary: Whichas Textbook Input, PlotQuestions*From*: Bill Rowe <readnewsciv at earthlink.net>*Date*: Wed, 9 Feb 2005 09:27:58 -0500 (EST)*Sender*: owner-wri-mathgroup at wolfram.com

On 2/8/05 at 5:31 AM, anonmous69 at netscape.net (Matt) wrote: >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)? I would do this by creating multiple definitions for f. For example, your particular example could be done as follows: f[x_] := Sin[x]/x /; x != 0; f[x_] := 1 /; x == 0; >As regards the Plot[] function, I'm puzzled as to why the following >doesn't give me an error when evaluated: >Clear[g]; >g[x_] := 1/x; >Plot[g[x], {x, -5, 5}]; >It seems as though it should, considering that x at zero is >undefined. However, Mathematica draws the graph as though the >function were just fine. This would only cause an error if the adaptive sampling routine choose 0 as one of the points to evaluate the function. The initial set of points used by Plot to sample the function is primarily determined by the range you specify in the call to Plot (-5 to 5 in your example) and PlotPoints (default value = 25). The adaptive sampling routine will evaluate the functions at additional plots depending on how much the function deviates from a straight line at the initial sample points. The amount of points added to the initial set is controlled by MaxBend and PlotDivision. Mathematica constructs the plot by simply connecting the plotted points with lines. So, if the sampling routine doesn't happen to choose the precise value where a singularity occurs, no error message happens. For example, do the following on your machine: Show[Block[{$DisplayFunction = Identity}, plot = Plot[Sin[x]/x, {x, -5, 5}]; ListPlot[Join@@First/@Cases[plot,_Line, Infinity], PlotStyle -> PointSize[0.015]]], plot, PlotRange -> {{-0.1, 0.1}, {0.999, 1}}]; This shows the curve and sampled points. And on my machine, quite clearly shows x = 0 was not one of the sampled points. In principle, it should be possible to cause Plot to sample at the signularity with the proper choices for PlotPoints, the range to be sampled, PlotDivision and MaxBend. But I lack enough knowledge to demonstrate this. Also, even if I could demonstrate this on my machine that would offer no assurance you would see the same on your machine. Differences in floating point hardware could easily cause Mathematica to obtain different sampling points with the same settings. -- To reply via email subtract one hundred and four

**Re: bugs in Mathematica 5.1**

**64-bit pentium**

**Re: bugs in Mathematica 5.1**

**64-bit pentium**