I would like to optimize evaluation of the function defined as an integral:
f[x_]:= NIntegrate[g[s],{s,0,x}]
the function g[x] can be an Interpolating function. The problem is that when I want to generate a Table of points
Table[f[x],{x,0.,200.,10.}]
function f[x] need to reintegrate the previous domain which is a waste of time because I calculated this value previously. I am thinking of a function definition that stores limits of integration and the value of the NIntegrate and when I call it for different argument it just integrates the missing part and adds it to the stored variable. For example:
f[2.] = NIntegrate[g[s],{s,0.,2.}]
f[4.] = NIntegrate[g[s],{s,2.,4.}] + f[2.]
f[3.] = f[4.] - NIntegrate[g[s],{s,3.,4.}]
With this function definition creating a list of values would be much faster. Is something like this possible in Mathematica 11.0?
Comments
Post a Comment