]> gitweb.factorcode.org Git - factor-unmaintained.git/blobdiff - math/newtons-method/newtons-method.factor
unmaintained: New home for misfit Factor vocabularies.
[factor-unmaintained.git] / math / newtons-method / newtons-method.factor
diff --git a/math/newtons-method/newtons-method.factor b/math/newtons-method/newtons-method.factor
new file mode 100644 (file)
index 0000000..4b53b12
--- /dev/null
@@ -0,0 +1,18 @@
+! Copyright (c) 2008 Reginald Keith Ford II.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel math math.derivatives ;
+IN: math.newtons-method
+
+! Newton's method of approximating roots
+
+<PRIVATE
+
+: newton-step ( x function -- x2 )
+    dupd [ call ] [ derivative ] 2bi / - ; inline
+
+: newton-precision ( -- n ) 13 ; inline
+
+PRIVATE>
+
+: newtons-method ( guess function -- x )
+    newton-precision [ [ newton-step ] keep ] times drop ;