Re: [Haskell-cafe] How to use roots package?

2011-03-23 Thread James Cook

On Mar 23, 2011, at 6:57 PM, Henning Thielemann wrote:


James Cook schrieb:

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 thought that the mosts Haskellish way to do numerical iterations  
is to

generate a list of successive approximations (by List.iterate, of
course) and then let the user choose where and why he wants to abort  
the

list, and thus the iteration.



That's probably true, and the same module exports a function that does  
so.  But sometimes you just want to ask "what is the root?", and get  
an answer without taking (possibly literally) forever.


Overall, the code is relatively un-Haskellish to begin with though.   
It was assembled in a short period of time in order to simply have  
code that performs the task, and hasn't really been touched since.


-- James___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to use roots package?

2011-03-23 Thread Henning Thielemann
James Cook schrieb:

> 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 thought that the mosts Haskellish way to do numerical iterations is to
generate a list of successive approximations (by List.iterate, of
course) and then let the user choose where and why he wants to abort the
list, and thus the iteration.


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to use roots package?

2011-03-20 Thread Edward Kmett
If your function has nice derivatives, you may want to look at the Newton
implementation in

http://hackage.haskell.org/packages/archive/ad/0.44.4/doc/html/Numeric-AD-Newton.html#v:findZero

or
if you have enough derivatives, you can even move up to the next Householder
method at Numeric.AD.Halley.findZero

These have the benefit of using exact derivatives, and returning a stream of
successively better approximations.

-Edward


On Fri, 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?
>
> Thanks in advance.
> — Artyom.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to use roots package?

2011-03-20 Thread Artyom Kazak
Oh. I have taken a wrong approach to the problem.

I have written Newton method with cutting precision if it's more than
N digits, and it finds an answer practically in no time. But still,
it's very good, thank you!

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to use roots package?

2011-03-18 Thread James Cook

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
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to use roots package?

2011-03-18 Thread Antoine Latter
On Fri, Mar 18, 2011 at 6: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?
>

Either choice looks like it would work fine - however using a newtype
wrapper around an existing instance of FindRoot would have the least
amount of code duplication, I think.

I recommend contacting the maintainer of the package about getting
their input, and about solving the problem in the package itself.

Antoine

> Thanks in advance.
> — Artyom.
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to use roots package?

2011-03-18 Thread Artyom Kazak


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?


Thanks in advance.
— Artyom.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe