0
$\begingroup$

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:

enter image description here

Instead of like this:

enter image description here

Update 12:38 AM May 22:

lista = DeleteCases[list, a_ /; a[[1]] >= 6]
listb = DeleteCases[list, a_ /; a[[1]] <= 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

enter image description here

However

dg[5]

0

I guess I need to get this to be indeterminate.

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

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

$\endgroup$
0
0
$\begingroup$

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...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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