5
$\begingroup$

I am trying to take the derivative of an interpolated function. I am given the function values and the derivatives at some irregular points. Here is my minimal working example to reproduce the error:

i = Interpolation[Table[{{2 t}, Sin[t], Cos[t]}, {t, 0, 4, 0.01}]]
Plot[i[t], {t, 0, 4}]

The plot looks fine

Plot[i'[t], {t, 0, 4}]

while the derivative is not ok

Apparently the interpolation is working, but not the derivative. Is there something I am doing wrong or is this a bug?

$\endgroup$

2 Answers 2

7
$\begingroup$

Remember the chain rule. You feed Interpolation with very contradictory information: The first derivative does not fit the parameterization of the curve.

This works better:

i = Interpolation[Table[{{2 t}, Sin[t], 1/2 Cos[t]}, {t, 0., 4., 0.01}]];
GraphicsRow[{
  Plot[i[t], {t, 0, 4}],
  Plot[i'[t], {t, 0, 4}]
  }]

enter image description here

Alternatively, you may use

i = Interpolation[Table[{{t}, Sin[t], Cos[t]}, {t, 0., 4., 0.01}]];
$\endgroup$
1
  • 1
    $\begingroup$ @Mr.Wizard Of course you're right. I removed it. $\endgroup$ Commented Mar 19, 2019 at 21:04
5
$\begingroup$

There is no error.

Given

f = Interpolation[Table[{{2 t}, Sin[t], Cos[t]}, {t, 0, 4, 0.01}]]

when you make the plot

Plot[f[t], {t, 0, 8}]

plot_1

it looks like a nice smooth curve which should have a smooth derivative, but if you plot a small section of the domain, like this

Plot[f[t], {t, 0, .1}]

plot_2

you see it is actually highly oscillatory, which explains your derivative plot.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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