I'm trying to integrate numerically in 6 dimensions a very long expression and I read about the option to NIntegrate
a compiled function which should be faster. However, this is not the case. I have tried a simple example with just 3 variables.
g[x_, y_, z_] := Sin[x]^2 y Exp[z];
f = Compile[{{x, _Real}, {y, _Real}, {z, _Real}}, g[x, y, z]];
f2[x_?NumericQ, y_?NumericQ, z_?NumericQ] := f[x, y, z];
And now the integrals and the output:
NIntegrate[f2[x, y, z], {x, 0, 100}, {y, 0, 10}, {z, 0, 9}]//Timing
{2.335434,2.03437*10^7}
NIntegrate[g[x, y, z], {x, 0, 100}, {y, 0, 10}, {z, 0, 9}]//Timing
{0.316207,2.03437*10^7}
Can I do anything to improve the speed of the integral of the compiled function?
Comments
Post a Comment