factor/extra/math/newtons-method/newtons-method.factor

12 lines
367 B
Factor
Raw Normal View History

2008-07-22 04:31:11 -04:00
! Copyright © 2008 Reginald Keith Ford II
! 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
: newton-step ( x function -- x2 ) dupd [ call ] [ derivative ] 2bi / - ;
: newton-precision ( -- n ) 7 ;
PRIVATE>
: newton-method ( guess function -- x ) newton-precision [ [ newton-step ] keep ] times drop ;