When handling derivatives of a interpolated function, I often use the following function
makeDeriv[f_InterpolatingFunction] = D[ f[x], x]
Then, I can define the derivative of f
, by defining a downvalue as
interpolated = Range[5]^2 // Interpolation;
deriv[x_] = makeDeriv[interpolated]; (* To find a derivative once and then to use it later. *)
deriv[3] (* Find a numerical value now*)
The purpose of this construct is to find the derivative once, and then use it later whenever I want to take derivatives.
(As a side question: will that be a better way than computing it from f
every time for each numerical argument I will be interested?)
But then, if I want to define a similar function inside the Module
, it does not seem to work, i.e.,
Module[ { qq},
qq[x_] = makeDeriv[interpolated];
qq[2]
](*It works!!*)
However,
Module[ { qq, int = interpolated},
qq[x_] = makeDeriv[int];
qq[2]
](*It does not work!!*)
Please explain why it happens and how to circumvent this problem.
(As another side question, let me know how to define the derivative of interpolation function properly.)
makeDeriv[f_InterpolatingFunction] := D[ f[x], x]
,deriv[x_] := makeDeriv[interpolated]
, andqq[x_] := makeDeriv[interpolated]
? The ":" might help. $\endgroup$