I am trying to find a root to an equation f[k,...]==0 numerically, where k is the variable I am solving for. Using both NSove as well as FindRoot I get the Error: Encountered non-numerical value for a derivative at t$50961 == 0'.

I am not sure why it talks about t in the error message, since the variable I am solving for is named k. t is the time variable of an integration which is performed inside of the function f. But for the root finding algorithm that should not be important.

Anyway, I thought that the algorithms Mathematica is trying to apply might not be suited to solve my equation. I thought that nothing could go wrong with the bisection method, but I cannot find it precoded in Mathematica.

I know that it is not hard to code it up. But is there really no precoded bisection method already available?


  • $\begingroup$ f[k,...]==0 ?, I don't see any equation ? It's impolite of you to expect an answer without providing the code to reproduce. $\endgroup$ Jul 15 '20 at 14:27
  • $\begingroup$ Dear Mariusz, The function f which I have written here is a very complicated procedure, which I cannot plug into this forum. The core question is simple and foesn't require knowledge of this function: "Is there a bisection method precoded in Mathematica, yes or no?" I really do not think that is impolite to ask. $\endgroup$
    – Britzel
    Jul 15 '20 at 14:40
  • 4
    $\begingroup$ There's Method -> "Brent" but not a bisection method. One can consider Brent's Method an improvement of the bisection method. Search this site if you really want an implementation of the bisection method. Others have written some code for it. $\endgroup$
    – Michael E2
    Jul 15 '20 at 14:41
  • $\begingroup$ As shown in the documentation, "FindRoot[lhs == rhs, {x, Subscript[x, 0], Subscript[x, 1]}] searches for a solution using Subscript[x, 0] and Subscript[x, 1] as the first two values of x, avoiding the use of derivatives." $\endgroup$
    – Bob Hanlon
    Jul 15 '20 at 14:42
  • 2
    $\begingroup$ There's a bisection method right here . Use bisect = ResourceFunction["BisectionMethodFindRoot"] $\endgroup$
    – flinty
    Jul 15 '20 at 15:14

There's a bisection method right here.

Use bisect = ResourceFunction["BisectionMethodFindRoot"]

bisect = ResourceFunction["BisectionMethodFindRoot"];
f[x_] := Cosh[2 Sinh[x^3 - 1] Exp[-x^2]] - 3
root = bisect[f[x], {x, 0.25, 1.0}, 9, 10000]
Plot[f[x], {x, 0, 2}, PlotRange -> {-2, 3}, 
 Epilog -> {Red, PointSize[Large], Point[{x /. root, 0}]}]

point root bisection

  • $\begingroup$ thanks a lot! You definitely answered my question, which is why I marked it as answer. ; ) Unfortunately I still get the error which I described in my starting post, also with the bisection method. It is really strange, since my function works as standalone function, but it doesn't work as function which is fed to bisect. The error which I get is happening in an NDSolve command which is nested inside my function. I will try to create a minimal example demonstrating this problem and open another thread for that. Anyway, thanks for the bisect! $\endgroup$
    – Britzel
    Jul 15 '20 at 19:43
  • $\begingroup$ @Britzel do you just need to pattern test the arguments of your function as NumericQ ? f[x_?NumericQ] := .... Based on that error t$50961 I'd guess you have a Module in your function, correct? $\endgroup$
    – flinty
    Jul 15 '20 at 20:00
  • $\begingroup$ That solved it, thank you so much! And yes, you were right, my function contained a Module, and in that module a set of ODEs was solved with NDSolve. The error occurred in NDSolve. So just that I understand what was going on: The way I defined my function it did not check for the argument to be numeric. And when plugging it into NSolveor FindRood, it somehow got non-numerical values passed, which led to the error? Anyway, thank you so much!! $\endgroup$
    – Britzel
    Jul 16 '20 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.