From: Sjoerd C. de Vries on
Hi Benjamin,

You could increase MaxRecursion and/or MaxPoints

Plot[s[x], {x, 0, 1},MaxRecursion -> 15]

Cheers -- Sjoerd


On Mar 10, 1:30 pm, Benjamin Hell <h...(a)exoneon.de> 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.


From: Peter Pein on
Am 10.03.2010 12:30, schrieb Benjamin Hell:
> 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.
>

Try:

Plot[s[x], {x, 0, 1}, Exclusions -> None]

hth


From: Raffy on
On Mar 10, 3:30 am, Benjamin Hell <h...(a)exoneon.de> 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.

Plot[..., MaxRecursion -> 15]

From: gekko on
On Mar 10, 10:30 pm, Benjamin Hell <h...(a)exoneon.de> 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.

It looks like the point x == 0.5 is being picked up as a possible
discontinuity and so the plot does not attempt to join at this point.
You can disable this using the Exclusions option:

Plot[s[x], {x,0,1}, Exclusions->None]

Cheers, P.

From: dh on
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(a)metrohm.com>
Internet:<http://www.metrohm.com>