# Efficiently Plotting NIntegrate with Variable Integration Limit [duplicate]

Consider $g(x)$ which is mathematically defined as

$g(x) = \int^{x}_{x_0} f(x') dx'$ such that $x\in\{x_0,x_{max}\}$.

If $f(x)$ can only be integrated numerically, one could define the following Mathematica function

g[x_]:= NIntegrate[f[xPrime],{xPrime,x0,x}]


Plotting this would take an eternity since every time x increases by an increment, the integral must be re-evaluated from x0 to the new x again and again. How can one efficiently plot $g(x)$ such that the plotting time is on the order of evaluating $g(x_{max})$? Equivalently, what is the most efficient way to generate an InterpolatingFunction for $g(x)$ over the range $x_0$ to $x_{max}$?

Note: Conversion to differential equation and using NDSolve is not a valid method as suggested here.

Note: Related but not a duplicate of "Plotting results of NIntegrate with variable integration limit".

• Plotting g = NDSolveValue[{y'[x] == f[xPrime], y[x0] == 0}, y, {xPrime, x0, xmax}] seems a valid method to me. Why do you say it's not? Please show an f that it does not work on. – Michael E2 Dec 11 '17 at 12:02
• Possible duplicates: (23854), (47580) – Michael E2 Dec 11 '17 at 12:25