Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

There were some related questions to this one, but in this case we have the function value, the first derivative and the second derivative all equal (that was actually the problem I was solving).

We have:

f[x_] := Piecewise[{{3 x^2 - 3 x + 1, x >= 1}, {x^3, x < 1}}]
Plot[f[x], {x, 0, 1.5}]

The answer in those other questions was to use "Exclusions -> None" and it can be used here, but why is this happening since we are good in all derivative information?


Some examples of the related questions are:

share|improve this question
I'm not sure that I should be saying this, especially since you are such an experienced user, but I think it would help if you provided the link to the other questions that you were mentioning. –  Vincent Tjeng Jan 13 '14 at 4:00
I have added three examples. Regards –  Amzoti Jan 13 '14 at 4:13
I think Mma will simply put an exclusion at predefined positions for various function types. E.g. for any HeavisideTheta it puts an exclusion to where the argument is zero; for any Piecewise function it puts an exclusion inbetween the pieces. It won't perform additional analysis to figure out that the function is in fact continuous in your case, it just does what it would do for all Piecewise functions. Not very surprising IMO. Note that the discontinuity detection is not numerical, it's symbolic. –  Szabolcs Jan 13 '14 at 5:28
@Szabolcs f[x_] := Piecewise[{{3 x^3 - 3 x + 1, x >= 1}, {x^3, x < 1}}] + 3/10 –  belisarius Jan 13 '14 at 6:22
Also related: (35067) –  Mr.Wizard Jan 13 '14 at 8:21

1 Answer 1

up vote 8 down vote accepted

Mathematica even leaves a gap when the expressions in Piecewise are equal, as long as Mathematica doesn't see the equality. Very simple example

test[x_] := Piecewise[{{x, x >= 1}, {Sqrt[x^2], x < 1}}]
Plot[test[x], {x, 0, 2}, PlotStyle -> Thick]

Mathematica graphics

When you replace Sqrt[x^2] by x, no gap.

What you have to understand is that the cracks are features when you use Piecewise because usually a piecewise function has jumps or discontinuities. Mathematica really just splits the plot, when it sees Piecewise and cannot determine a simple equality between the expressions.

This is a bit unfortunate, because although it is correct most of the time, users will always complain why this doesn't work like they want it.

My short answer: If you don't want cracks, then use Exclusions->None or make sure Mathematica doesn't see your Piecewise

f[x_?NumericQ] := Piecewise[{{3 x^2 - 3 x + 1, x >= 1}, {x^3, x < 1}}]
Plot[f[x], {x, 0, 1.5}]

Mathematica graphics

Here, the NumericQ hinders Mathematica to evaluate your expression for non-numeric values and the only chance it has is to put a number in and get a number out :-)

Btw, let's give Mathematica something to think about and add again a definition for f where it sees the Piecewise. It doesn't matter what it sees, so screw it:

f[x_] := Piecewise[{{"Ding", x < .4}, {"Dong", x < .8}, {"Boing", x < 1.2}}, "Blub"];

And now do that nice plot again

Plot[f[x], {x, 0, 1.5}]

Mathematica graphics

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.