factor/unmaintained/math/newtons-method/newtons-method.factor

19 lines
454 B
Factor
Raw Normal View History

2008-11-07 01:24:32 -05:00
! Copyright (c) 2008 Reginald Keith Ford II.
2008-10-03 03:19:03 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-07-22 20:45:13 -04:00
USING: kernel math math.derivatives ;
2008-07-24 01:09:01 -04:00
IN: math.newtons-method
2008-07-22 04:31:11 -04:00
2008-11-07 01:24:32 -05:00
! Newton's method of approximating roots
2008-07-22 04:31:11 -04:00
<PRIVATE
2008-10-03 03:19:03 -04:00
: newton-step ( x function -- x2 )
dupd [ call ] [ derivative ] 2bi / - ; inline
: newton-precision ( -- n ) 13 ; inline
2008-07-22 04:31:11 -04:00
PRIVATE>
2008-10-03 03:19:03 -04:00
: newtons-method ( guess function -- x )
newton-precision [ [ newton-step ] keep ] times drop ;