# Table in NIntegrate

I have an integral that I want to evaluate it once and store its values in a table so that I don't run the integration each time that I want to plot it. Its form is int[x_,y_]:=NIntegrate[f[z],{z,x,y}] with the functional form of f[z] being irrelevant for the time being and x,y being in the range of [1,1000] and specified each time that I plot it. How do I do a table that essentially is a function of x,y (and takes the values from the table rather than re-integrating everything each time)?

• Instead of defining the function, define a table: ints = Table[NIntegrate[f[x], {z, x, y}], {x, 1, 2}, {y, 3, 6}]. Either that, or memoize: int[x_, y_] := int[x, y] = NIntegrate[f[z],{z,x,y}], but I recommend the first. – march Jan 8 '19 at 17:03
• Ok, if I go for the first method, how to I plot it afterwards from say x=1 to y=1000? – hal Jan 8 '19 at 17:10
• I don't understand what you mean by "plot it from x = 1 to y = 1000", because those are two different variables. – march Jan 8 '19 at 17:11
• Yeah my mistake I didn't explain it properly. By defining the table essentially I have a function ints[a,b] and I want to be able to do plots like Plot[ints[1,r],{r,1,1000}] and Plot[ints[r,1],{r,1,1000}]. Is something like that possible? Thank you – hal Jan 8 '19 at 17:19
• Use Interpolation: data = Table[{{x, y}, NIntegrate[f[z], {z, x, y}]}, {x, 1, 1000, 999/99}, {y, 1, 1000, 999/99}]; ints = Interpolation[data]; – Bob Hanlon Jan 8 '19 at 18:03

NDSolve will compute a numeric antiderivative.

Example:

ClearAll[f];
f[t_] := Re@Zeta[1/2 + Sqrt[t] I];

Plot[f[t], {t, 1, 1000}]


The antiderivative:

ListLinePlot@NDSolveValue[{y'[t] == f[t], y[1] == 0}, y, {t, 1, 1000}]


Here's the definite integral int[x, y]:

ClearAll[int];
With[{F = NDSolveValue[{y'[t] == f[t], y[1] == 0}, y, {t, 1, 1000}]},
int[x_, y_] := Subtract @@ F[{y, x}]
];

Plot3D[int[x, y], {x, 1, 1000}, {y, 1, 1000}]


For greater accuracy, use

NDSolveValue[{y'[t] == f[t], y[1] == 0}, y, {t, 1, 1000}, InterpolatingOrder -> All]