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
6 ! Newton's method of approximating roots
10 : newton-step ( x function -- x2 )
11 dupd [ call ] [ derivative ] 2bi / - ; inline
13 : newton-precision ( -- n ) 13 ; inline
17 : newtons-method ( guess function -- x )
18 newton-precision [ [ newton-step ] keep ] times drop ;