]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/math/newtons-method/newtons-method.factor
4b53b1222d913e7472e7ba87f6b8ecc439b749dd
[factor.git] / unmaintained / math / newtons-method / newtons-method.factor
1 ! Copyright (c) 2008 Reginald Keith Ford II.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel math math.derivatives ;
4 IN: math.newtons-method
5
6 ! Newton's method of approximating roots
7
8 <PRIVATE
9
10 : newton-step ( x function -- x2 )
11     dupd [ call ] [ derivative ] 2bi / - ; inline
12
13 : newton-precision ( -- n ) 13 ; inline
14
15 PRIVATE>
16
17 : newtons-method ( guess function -- x )
18     newton-precision [ [ newton-step ] keep ] times drop ;