I am working with interpolation function with some non-numerical arguments. A simplified version of the function I am working with is:

FUNC = Interpolation[{{0, a}, {1, b}, {2, c}}]

I would like to compute the derivative of FUNC with respect to a, b and c (for a general function value)

Potential solution: obtain the piecewise function that Interpolation generates. Problem: I do not know how to extract this piecewise function from FUNC.

  • $\begingroup$ Is not it the same as computing a derivative of the interpolating function? $\endgroup$
    – yarchik
    Sep 27 '16 at 8:52
  • $\begingroup$ No. Typically, the derivative would be FUNC'[x]. However, I do not want dFUNC/dx, but dFUNC/da, where a is one of the parameters specified above. $\endgroup$
    – Breugem
    Sep 27 '16 at 8:56
  • $\begingroup$ The piecewise function that the interpolating function represents depends on the interpolation method and the data. Here is one way: mathematica.stackexchange.com/a/59963/4999 $\endgroup$
    – Michael E2
    Sep 27 '16 at 10:23
  • $\begingroup$ This makes no sense because this derivative is not defined by your data unless it contains {0,a} and {0,a+some value}. $\endgroup$ Mar 25 '18 at 17:49
f[a_, b_, c_] = Interpolation[
   {{0, a}, {1, b}, {2, c}},
   InterpolationOrder -> 2];

xValues = Range[0, 2, 1/8];

fValues = f[a, b, c] /@ xValues // Simplify;

dfda[x_] = InterpolatingPolynomial[
   {xValues, D[#, a] & /@ fValues} // Transpose, x] //

(*  1/2 (2 - 3 x + x^2)  *)

Plot[dfda[x], {x, 0, 2},
 Frame -> True,
 FrameLabel -> (Style[#, 14, Bold] & /@
    {"x", "df / da"})]

enter image description here

EDIT: As Breugem suggested in his comment to this answer, working directly with the InterpolatingPolynomial is more straightforward.

fp[a_, b_, c_, x_] = 
 InterpolatingPolynomial[{{0, a}, {1, b}, {2, c}}, x] // Simplify

(*  a + (-a + b + 1/2 (a - 2 b + c) (-1 + x)) x  *)

D[fp[a, b, c, x], a] // Simplify

(*  1/2 (2 - 3 x + x^2)  *)
  • $\begingroup$ This is very good! The interpolating polynomial will become complex for large grids, in which a piecewise polynomial needs to be estimated, which brings us back to the original problem. I guess the most efficient way would be to generate an interpolating polynomial from the start $\endgroup$
    – Breugem
    Sep 27 '16 at 12:15
  • 1
    $\begingroup$ @Breugem Using an interpolating polynomial on more than a few points is usually a bad idea, unless your data is exact and you know a polynomial is an appropriate model. Piecewise interpolation is usually more appropriate. $\endgroup$
    – Michael E2
    Sep 27 '16 at 13:12
  • $\begingroup$ I agree:) This was my (potentially unclear) comment (i.e., we cannot use the InterpolatingPolynomial from the answer above) $\endgroup$
    – Breugem
    Sep 27 '16 at 13:50

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.