Re: Re: gaps in plot of piecewise function
- To: mathgroup at smc.vnet.net
- Subject: [mg108297] Re: [mg108220] Re: [mg108217] gaps in plot of piecewise function
- From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
- Date: Sat, 13 Mar 2010 07:54:49 -0500 (EST)
- References: <30604342.1268221205458.JavaMail.root@n11>
Hi, > The latter functions are equal for all x. Doesn't hold for the former two. yep, but Sin[x] == (I/2)/E^(I*x) - (I/2)*E^(I*x) // Simplify Manipulate[ Plot[Piecewise[{{Sin[x], x < 1.334}}, (I/2)/E^(I*x) - (I/2)* E^(I*x)], {x, 0, 3}, MaxRecursion -> mr, MeshStyle -> {Red, PointSize[0.005]}, Mesh -> All, PlotPoints -> pp, ImageSize -> 500], {{pp, 5, "PlotPoints"}, 3, 30, 1}, {{mr, 1, "MaxRecursion"}, 1, 10, 1}] > If you increase PlotPoints to well over a couple of hundred with > MaxRecursion at 15 I don't see a gap. "See" doesn't mean it's not there. Please set PlotPoints to 200 and MaxRecursion to 15 and check the zoomed result Manipulate[ Plot[Piecewise[{{Exp[1] x, x < 1}}, Exp[x]], {x, 0, 3}, MaxRecursion -> mr, MeshStyle -> {Red, PointSize[0.005]}, Mesh -> All, PlotPoints -> pp, ImageSize -> 500, PlotRange -> {{1 - zoom, 1 + zoom}, Automatic}], {{pp, 5, "PlotPoints"}, 3, 200, 1}, {{mr, 1, "MaxRecursion"}, 1, 15, 1}, {{zoom, 1}, 1, 0}] Cheers Patrick > Cheers -- Sjoerd > > > -----Original Message----- > > From: Patrick Scheibe [mailto:pscheibe at trm.uni-leipzig.de] > > Sent: 11 March 2010 14:23 > > To: David Park; Benjamin Hell; Sjoerd C. de Vries; Peter Pein; gekko; > > Matthias Hunstig > > Cc: mathgroup at smc.vnet.net > > Subject: Re: [mg108220] Re: [mg108217] gaps in plot of piecewise > > function > > > > Hi again, > > > > I hope everyone saw now that Exclusions->None or using not Piecewise > > but > > e.g. Which will do the trick. In the documentation it sounds to me that > > many functions are generally connected to Piecewise (look at Properties > > and Relations in the Piecewise doc). > > > > My question is, why would it be wrong to connect the plot in Piecewise > > when the Limits are the same? Following example: > > > > Manipulate[ > > Plot[Piecewise[{{Exp[1] x, x < 1}}, Exp[x]], {x, 0, 3}, > > MaxRecursion -> mr, MeshStyle -> {Red, PointSize[0.005]}, > > Mesh -> All, PlotPoints -> pp, > > ImageSize -> 500], {{pp, 5, "PlotPoints"}, 3, 30, > > 1}, {{mr, 1, "MaxRecursion"}, 1, 10, 1}] > > > > The function has the same limit at x->1 and the same derivative. I > > would > > clearly expect a plot without a gap even without the Exclusions > > options. > > Where am I wrong? > > > > Is it too unpredictable to check at least numerically the limits? > > But why is this working? > > > > Manipulate[ > > Plot[Piecewise[{{Sin[x], x < 1.334}}, Cos[ x - Pi/2]], {x, 0, 3}, > > MaxRecursion -> mr, MeshStyle -> {Red, PointSize[0.005]}, > > Mesh -> All, PlotPoints -> pp, > > ImageSize -> 500], {{pp, 5, "PlotPoints"}, 3, 30, > > 1}, {{mr, 1, "MaxRecursion"}, 1, 10, 1}] > > > > What bothers me is that when using PiecewiseExpand you get an > > equivalent > > presentation of one and the same function but you get different plots > > in > > an, say not really predictable way. > > > > Cheers > > Patrick > > > > On Thu, 2010-03-11 at 06:34 -0500, David Park wrote: > > > I'm not certain of the exact underlying mechanics, but basically > > because of > > > the steep curve as x -> 2 from below, and the piecewise function, > > > Mathematica sees a discontinuity and leaves a gap. The way to > > overcome this > > > is to use the Exclusions option. > > > > > > s[x_] := Piecewise[{{-Sqrt[2]/2*Sqrt[-x + 0.5] + 2, x < 0.5}, {2, > > > x >= 0.5}}]; > > > > > > Plot[s[x], {x, 0, 1}, > > > Exclusions -> None, > > > Frame -> True, > > > PlotRangePadding -> .1] > > > > > > > > > David Park > > > djmpark at comcast.net > > > http://home.comcast.net/~djmpark/ > > > > > > > > > From: Benjamin Hell [mailto:hell at exoneon.de] > > > > > > Hi, > > > I want to plot a piecewise function, but I don't want any gaps to > > appear > > > at the junctures. An easy example is: > > > > > > s[x_] := Piecewise[{{-Sqrt[2]/2*Sqrt[-x + 0.5] + 2, x < 0.5}, {2, x > > >= > > > 0.5}}]; > > > Plot[s[x], {x, 0, 1}] > > > > > > It should be clear, that the piecewise function defined above is > > > continuous, even at x=0.5. So there should not be any gaps appearing > > in > > > the plot, but they do. Maybe it's a feature of mathematica, but > > > nevertheless I want to get rid of the gaps. Any suggestions on how to > > > achieve that. > > > > > > > > > Thanks in advance. > > > > > > > > > >