NDSolve has an interface for repeatedly solving an equation with different initial conditions without having to analyze the equation and set up the solving algorithm each time. This can improve performance dramatically. For example,
nd = First@NDSolve`ProcessEquations[{y'[t] == -y[t], y[0] == 1}, {y}, t]
(* NDSolve`StateData[<0.>] *)
solve[y0_] := Module[{}, nd = First@NDSolve`Reinitialize[nd, y[0] == y0];
NDSolve`Iterate[nd, 1]; NDSolve`ProcessSolutions[nd]]
Timing[NDSolve[{y'[t] == -y[t], y[0] == #}, y, {t, 0, 1}]&/@Range[0.001, 1, 0.001]]//First
(* 0.527396 *)
Timing[solve /@ Range[0.001, 1, 0.001]] // First
(* 0.250309 *)
Is there an analogous interface to NIntegrate that would allow me to process the integral once, then do integrations using the same integration method (as chosen by NIntegrate) repeatedly using different constants in the integrand and/or different limits of integration?
solvewithParametricNDSolveValue:pa = ParametricNDSolveValue[{y'[t] == -y[t], y[0] == a}, y, {t, 0, 1}, a]; pa /@ Range[0.001, 1, 0.001]; // AbsoluteTiming– xzczd Feb 09 '17 at 11:57