Message Boards Message Boards

Finding the Derivative of an Interpolated Function

Posted 1 year ago

Comparison between the derivatives of the symbolic function and the interpolated function:

 ex = Cos[x];

d = Interpolation[Table[ex, {x, 0 \[Degree], 360 \[Degree], 1 \[Degree]}], InterpolationOrder -> 6];

Plot[{d[t], d'[t]}, {t, 1, 361}]

Plot[{ex, D[ex, x]} // Evaluate, {x, 0 \[Degree], 360 \[Degree]}]

For example for x = 45[Degree]:

The results for the symbolic and interpolated functions are identical:

{Cos[45 \[Degree]], d[46]}
{1/Sqrt[2], 1/Sqrt[2]}

But for derivatives, the results are different. That's it?

{D[ex, x] /. x -> 45 \[Degree], d'[46]} // N
{-0.707107, -0.0123413}

Regards,

Sinval

POSTED BY: Sinval Santos
5 Replies
Posted 1 year ago

Thanks for your attention Henrik. I will correct my error.

Also thank you for the attention Gianluca. This procedure worked.

POSTED BY: Sinval Santos

I don't know what you wanted as the correct result. The way you have set up your Interpolation, its domain is the interval [1, 361] of the reals, and knows nothing of degrees. This way the two derivatives agree:

f = Interpolation[Table[{x, Cos[x]}, {x, 0 °, 360 °, 1 °}], 
  InterpolationOrder -> 6]
f'[45 °] // N
POSTED BY: Gianluca Gorni
Posted 1 year ago

Hello Henrik. The substitution of x by 45 degrees occurs after computing the derivative of Cos[x], which is equal to -Sin[x]..

D[ex, x] /. x -> 45 \[Degree] // N

Which returns:

-0.707107

However, the number 46 is equivalent to x=45 degrees in the interpolated function and, in my opinion, d'[46] should return the value of the derivative of Cos[x] for x=45 degrees.

d'[46] // N

Which returns:

-0.0123413

Don't you think they should be the same?

POSTED BY: Sinval Santos

Well, I see your point. But you did not interpolate Cos[x] but Cos[x \[Degree]]. So when you want to get the same results, you rather have to calculate ``d'[46]/[Degree]} // N``` - that I tried to indicate with my first answer.

POSTED BY: Henrik Schachner

This is because you have:

enter image description here

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract