]> gitweb.factorcode.org Git - factor.git/blob - extra/math/secant-method/secant-method.factor
Merge branch 'master' of git://factorcode.org/git/factor
[factor.git] / extra / math / secant-method / secant-method.factor
1 ! Copyright © 2008 Reginald Keith Ford II
2 ! Secant Method of approximating roots
3
4 USING: kernel math math.function-tools math.points math.vectors ;
5 IN: math.secant-method
6
7 <PRIVATE
8 : secant-solution ( x1 x2 function -- solution ) [ eval ] curry bi@ linear-solution ;
9 : secant-step ( x1 x2 func -- x2 x3 func ) 2dup [ secant-solution ] 2dip swapd ;
10 : secant-precision ( -- n ) 15 ;
11 PRIVATE>
12 : secant-method ( left right function -- x ) secant-precision [ secant-step ] times drop + 2 / ;
13 ! : close-enough? ( a b -- t/f ) - abs tiny-amount < ;
14 ! : secant-method2 ( left right function -- x ) 2over close-enough? [ drop average ] [ secant-step secant-method ] if  ;