Skip to main content
10 events
when toggle format what by license comment
Jan 8, 2018 at 16:08 comment added halirutan @Joe Are you referring to that 50µs difference that is spent on evaluating the g[x] (i.sstatic.net/Js0pm.png)? I was under the impression your example is an example. Have you tried what happens if you indeed have a complex expression with thousands of terms? Additionally, I wasn't aware of your other post that clears up the background of your question very much. See for instance this example i.sstatic.net/7mK9y.png You should consider visiting the Mathematica Chat every once in a while where things can be discussed better.
Jan 8, 2018 at 15:27 comment added Jojo Consider the following code, g = Compile[{x}, Evaluate[f[x]]]; FindRoot[g, {3.99}] // RepeatedTiming FindRoot[g[x], {x, 3.99}] // RepeatedTiming. You will see that the second call to FindRoot does not benefit from the speed increase of compiling g. See here for some further discussion; mathematica.stackexchange.com/questions/161888/…
Jan 8, 2018 at 15:17 comment added halirutan @Joe You can use it like FindRoot[f[x, 4], {x, 3.99}]. I guess I'm still not seeing your point. Didn't you want to call FindRoot that way without recompilation? f is compiled exactly once no matter how often you call FindRoot for different values of a.
Jan 8, 2018 at 15:11 comment added xzczd I think RuntimeOptions -> "EvaluateSymbolically" -> False will be a better choice here compared to _?NumericQ :)
Jan 8, 2018 at 15:07 comment added Jojo Oh yes right you are my code was doing nothing. I missed the Evaluate in my question I've edited that in now. I'm not really sure how your f[x_?NumericQ, a_?NumericQ] := fc[x, a] answers my problem, I don't see how to put this into FindRoot. Yes thanks for pointing out about the range of the a parameter, this is something that I'm taking care of.
Jan 8, 2018 at 14:20 comment added Henrik Schumacher Huh? Who downvoted here? People go crazy...
Jan 8, 2018 at 13:37 comment added halirutan See my edit then.
Jan 8, 2018 at 13:37 history edited halirutan CC BY-SA 3.0
added 901 characters in body
Jan 8, 2018 at 13:27 comment added Jojo I want to compile only once for all values of a. This was what I meant in my wording of the original question, but I have edited to be more clear.
Jan 8, 2018 at 13:00 history answered halirutan CC BY-SA 3.0