I am having a misunderstanding with Mathematica about integration of InterpolatingFunction. Consider this example:

n = 300
start = 0;
end = 6 π;
testdata = Table[{N[i*end/n], N@Sin[i*end/n]}, {i, 0, n}];
ftest = Interpolation[testdata, InterpolationOrder -> 1]

Now integrate once the interpolating function:

iftest[x_] := Integrate[ftest[t], {t, start, x}];
Plot[{iftest[x], 1 - Cos[x]}, {x, start, end}, 
 PlotStyle -> {Directive[Orange, Thickness[0.01]], Blue}]

Giving as expected. Now, let's integrate once more:

iiftest[x_] := Integrate[iftest[t], {t, start, x}];

then upon trying to plot, i receive complaint: NIntegrate::nlim: t = t is not a valid limit of integration.. So I try:

iiftest[start + 0.2]

only to receive:

enter image description here



1 Answer 1


An easy workaround, because ftest is a pure function(interpolation object), using Derivative

Plot[{Derivative[-1][ftest][t], Derivative[-2][ftest][t]}, {t, start,end}]

enter image description here


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.