2008-08-02 13:57:17 -04:00
|
|
|
|
! Copyright <20> 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 04:31:11 -04:00
|
|
|
|
! Newton's Method of approximating roots
|
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
|
|
|
|
|
|
|
|
|
<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 ;
|