NAntiDerivative function for using NDSolve to compute antiderivatives

*To*: mathgroup at smc.vnet.net*Subject*: [mg83380] NAntiDerivative function for using NDSolve to compute antiderivatives*From*: "Andrew Moylan" <andrew.j.moylan at gmail.com>*Date*: Sun, 18 Nov 2007 06:10:03 -0500 (EST)

Pretty often on this newsgroup I notice users computing antiderivatives numerically like this: g[x_?NumericQ] := NIntegrate[f[t], {t, 0, x}]. This is slow when g needs to be evaluated many times. The usual remedies are to call FunctionInterpolation on g, or, what is usually better, replace the calls to NIntegrate with a call to NDSolve. I encounter this a lot so I have a function, NAntiDerivative, that solves it using the NDSolve method. The definition of g, above, is replaced by g = NAntiDerivative[f]. NAntiDerivative automatically calls NDSolve as required, and remembers the results of previous calls to make future evaluations faster. I thought other people might find it useful. It's at http://andrew.j.moylan.googlepages.com/mathematica.