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]];
  • 3
    $\begingroup$ FindRoot is not compilable: Compile`CompilerFunctions[] // Sort $\endgroup$ Jun 13, 2018 at 8:47
  • $\begingroup$ Also, when you call it like this, FindRoot is probably/hopefully sufficiently optimized that you won't gain anything by Compileing. $\endgroup$ Jun 13, 2018 at 20:19
  • 1
    $\begingroup$ I closed this as a duplicate of our "list of compilable functions" post. There is really not much more to say except that in basically all cases, you should not try to put 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$
    – halirutan
    Jun 16, 2018 at 1:35


Browse other questions tagged or ask your own question.