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

12 lines
368 B
Factor
Raw Normal View History

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