]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/math/secant-method/secant-method.factor
factor: trim using lists
[factor.git] / extra / math / secant-method / secant-method.factor
index 2089dde848e292b31362fb53e14f5df38f188fca..ae4f524ffed1268c26aa8d33180abeb8ba488050 100644 (file)
@@ -1,14 +1,27 @@
-! Copyright © 2008 Reginald Keith Ford II
-! Secant Method of approximating roots
-
-USING: kernel math math.function-tools math.points math.vectors ;
+! Copyright (c) 2008 Reginald Keith Ford II.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel math math.function-tools math.points ;
 IN: math.secant-method
 
+! Secant method of approximating roots
+
 <PRIVATE
-: secant-solution ( x1 x2 function -- solution ) [ eval ] curry bi@ linear-solution ;
-: secant-step ( x1 x2 func -- x2 x3 func ) 2dup [ secant-solution ] 2dip swapd ;
-: secant-precision ( -- n ) 11 ;
+
+: secant-solution ( x1 x2 function -- solution )
+    [ eval ] curry bi@ linear-solution ;
+
+: secant-step ( x1 x2 func -- x2 x3 func )
+    [ secant-solution ] 2keep swapd ;
+
+: secant-precision ( -- n ) 15 ; inline
+
 PRIVATE>
-: secant-method ( left right function -- x ) secant-precision [ secant-step ] times drop v+ 2 v*n ;
+
+: secant-method ( left right function -- x )
+    secant-precision [ secant-step ] times drop + 2 / ;
+
 ! : close-enough? ( a b -- t/f ) - abs tiny-amount < ;
-! : secant-method2 ( left right function -- x ) 2over close-enough? [ drop average ] [ secant-step secant-method ] if  ;
\ No newline at end of file
+
+! : secant-method2 ( left right function -- x )
+    ! 2over close-enough?
+    ! [ drop average ] [ secant-step secant-method ] if  ;