[Haskell-cafe] How to use roots package?

James Cook mokus at deepbondi.net
Sat Mar 19 02:22:27 CET 2011


On Mar 18, 2011, at 7:39 PM, Artyom Kazak wrote:

>
> Hi Café!
>
> roots (http://hackage.haskell.org/package/roots) is a package to  
> solve equations like "f(x)==0".
>
> In RootFinder class there is an 'defaultNSteps' value, which is used  
> as maximal count of iterations functions like findRoot and traceRoot  
> can make. By default it is 250, but sometimes it's not enough. How  
> can I use another value instead of 250? Should I write my own  
> RootFinder instance, or findRoot function?
>

Those are both options,  as is to simply restart findRoot if it  
returns a 'Left' vaule.  I personally would incline toward a custom  
driver function (findRoot).  I should probably add one to the library  
that accepts a step limit and/or one that just iterates until  
convergence.

I'm curious, though - what sort of functions are you using, and what  
root finding algorithm, that it takes that long to converge?  And are  
you sure that it ever does, if it were allowed to run longer?   
Typically, for functions on Double, if an algorithm fails to converge  
within around 50 steps it's fairly likely that it never will -  
especially with an algorithm like bisection or Brent's method.  If  
you're using a higher precision type, then I probably need to change  
the default iteration limit to something more suited to the function  
type.

-- James


More information about the Haskell-Cafe mailing list