Re: gaps in plot of piecewise function
- To: mathgroup at smc.vnet.net
- Subject: [mg108250] Re: gaps in plot of piecewise function
- From: dh <dh at metrohm.com>
- Date: Thu, 11 Mar 2010 07:48:01 -0500 (EST)
- References: <201003101130.GAA10324@smc.vnet.net> <hnakkn$5tb$1@smc.vnet.net>
Hi Beata, you may e.g. use Reduce like: lines = t /. {Reduce[{deriv2func == 0, Element[t, Reals]}, t] // ToRules}; lines = Line[{{ #, -0.2}, {#, 0.2}}] & /@ lines; Plot[{deriv2func}, {t, First[First[date]], First[Last[date]]}, Frame -> True, GridLines -> Automatic, Epilog -> {Red, lines}] Daniel On 11.03.2010 12:36, Patrick Scheibe wrote: > Hi, > > short answer: use Which instead of Piecewise for plotting. > > Long answer: I assume it's a hack which should provide that piecewise > defined functions are not connected since in cases of step-functions it > is usually wanted that plots are not connected: > > step = Which[x< 0.5, 1, 0.5< x< 1, 0.5, True, 0] > step2 = PiecewiseExpand[step] > Plot[#, {x, 0, 2}]& /@ {step, step2} > > If you want to know a bit more detailed what happens in you example you > could compare the two plots with different settings for PlotPoints and > MaxRecursion: > > s[x_] := Piecewise[{{-Sqrt[2]/2*Sqrt[-x + 1/2] + 2, x< 1/2}}, 2]; > s2[x_] := Which[x< 1/2, -Sqrt[2]/2*Sqrt[-x + 1/2] + 2, True, 2]; > Column[Manipulate[ > Plot[#, {x, 0, 1}, MaxRecursion -> mr, > MeshStyle -> {Red, PointSize[0.005]}, Mesh -> All, > PlotPoints -> pp, ImageSize -> 500], > {{pp, 3, "PlotPoints"}, 3, 30, 1}, > {{mr, 1, "MaxRecursion"}, 1, 10, 1} > ]& /@ {s[x], s2[x]}] > > If you look really closely you see that the Piecewise-stuff gets always > disconnected, no matter how many plotpoints you use. In real-life you > just don't see that there is a gap when you have enough plotpoints and a > moderate setting for maxrecursion. > > Cheers > Patrick > > On Wed, 2010-03-10 at 06:30 -0500, Benjamin Hell wrote: >> 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. >> > > -- Daniel Huber Metrohm Ltd. Oberdorfstr. 68 CH-9100 Herisau Tel. +41 71 353 8585, Fax +41 71 353 8907 E-Mail:<mailto:dh at metrohm.com> Internet:<http://www.metrohm.com>
- References:
- gaps in plot of piecewise function
- From: Benjamin Hell <hell@exoneon.de>
- gaps in plot of piecewise function