How to compile this function or any function that uses lists and Part[] ?
f[x_?NumberQ] := FindRoot[x == Sin[t] - t, {t, 1}][[1, -1]];
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityHow to compile this function or any function that uses lists and Part[] ?
f[x_?NumberQ] := FindRoot[x == Sin[t] - t, {t, 1}][[1, -1]];
FindRoot
is not compilable:Compile`CompilerFunctions[] // Sort
$\endgroup$FindRoot
is probably/hopefully sufficiently optimized that you won't gain anything byCompile
ing. $\endgroup$FindRoot
in a compiled function. There might be some rare exceptions but usually, it is a bad idea. In general, you should be concerned about the speed of the function you want to find the roots for. If you have a very complex expression that can be compiled, then this might be worth a shot. $\endgroup$