Tag Info

New answers tagged

5

Compile f and use a memo-ized version of it Since it seems like NIntegrate decides to symbolically evaluate its argument first, I thought I'd force it not to by compiling the function f. This seems to make a significant difference: Clear[f, f1, g] g[x_] = Nest[f[x] + 1./# &, f[x], 500]; f1 = Compile[{x}, Sum[1/100 Erfc[-(x^2/k)], {k, 100}]]; ...


12

f[x_] := x^2 DownValues[h] = DownValues[f] /. f -> h; f[x_] := f[x] = h[x] h is now equal to the original f, and f is a memoized version of it. Some kinds of definitions would require a more specific replacement rule than /. f -> h, for example recursive functions.



Top 50 recent answers are included