# Interpolation and points of non-differentiability

I have some data, which if expressed by some elementary functions, would contain a non-differentiable point. I would like to be able to use something like interpolate to convert the data into a function and then differentiate it but somehow still preserve the non-differentiability property at that point.

MWE

list = Table[{j, Max[5, j]}, {j, 0, 15, 1}]

{{0, 5}, {1, 5}, {2, 5}, {3, 5}, {4, 5}, {5, 5}, {6, 6}, {7, 7}, {8,
8}, {9, 9}, {10, 10}, {11, 11}, {12, 12}, {13, 13}, {14, 14}, {15,
15}}


My data comes from a continuous function which is not differentiable at $x=5$.

fint = Interpolation[list]

dfint[x_] = D[fint[x], x]

Plot[dfint[x], {x, 0, 15}, AxesOrigin -> {0, -1}]


The Derivative looks like this:  Update 12:38 AM May 22:

lista = DeleteCases[list, a_ /; a[] >= 6]
listb = DeleteCases[list, a_ /; a[] <= 4]

{{0, 5}, {1, 5}, {2, 5}, {3, 5}, {4, 5}, {5, 5}}

{{5, 5}, {6, 6}, {7, 7}, {8, 8}, {9, 9}, {10, 10}, {11, 11}, {12,
12}, {13, 13}, {14, 14}, {15, 15}}

ga = Interpolation[lista]
gb = Interpolation[listb]

dga[x_] = D[ga[x], x]
dgb[x_] = D[gb[x], x]

g[x_] = Piecewise[{{ga[x], x <= 5}, {gb[x], x > 5}}]

dg[x_] = Piecewise[{{dga[x], x < 5}, {dgb[x], x > 5}}]


Doing this

Plot[dg[x], {x, 0, 15}, AxesOrigin -> {0, -1}]


gives However

dg

0


I guess I need to get this to be indeterminate.

• Just do dg[x_] = D[g[x], x] and then dg automatically becomes indeterminate...
– user484
May 22 '13 at 4:44
• You could use Piecewise[]'s default value; set it to Indeterminate instead of 0. May 22 '13 at 4:45
• @RahulNarain and J.M. great thanks! May 22 '13 at 5:09
• Look also at InterpolationOrder. May 22 '13 at 7:08
• @RahulNarain oh, yes, I wasn't focused enough
– Kuba
Mar 28 '14 at 2:57

Just do dg[x_] = D[g[x], x] and then dg automatically becomes indeterminate.

As suggested in a comment, you can use InterpolationOrder -> 1 and then fix the Indeterminate derivative.

ClearAll[list, fint, dfint]
list = Table[{j, Max[5, j]}, {j, 0, 15, 1}];
ListLinePlot@list

fint = Interpolation[list, InterpolationOrder -> 1]

Plot[fint[x], {x, 0, 15}, AxesOrigin -> {0, -1}]
dfint[x_] = D[fint[x], x]

Plot[dfint[x], {x, 0, 15}, AxesOrigin -> {0, -1}]
dfint@5
dfint@5 = Indeterminate;
dfint@5


It should be easy to come up with an algorithm that automatically sets all the Indeterminate derivatives of an InterpolationOrder -> 1 function...