Permalink
Browse files

Add docs directory and example files

  • Loading branch information...
1 parent 35be201 commit 0714e364c9b06c02cadaf52bd3a19a43b140409e Firman Wandayandi committed Jan 31, 2006
View
@@ -0,0 +1,59 @@
+================================
+PEAR::Math_Numerical_RootFinding
+================================
+
+$Id$
+
+
+INTRODUCTION
+============
+
+Math_Numerical_RootFinding is the package provide various Numerical Methods
+Root-Finding functions implemented in PHP, e.g Bisection, Newton-Raphson, Fixed
+Point and Secant.
+
+
+SUPPORTED METHODS
+=================
+
+ Methodname Callname
+ -----------------------------------------------------------------------------
+1. Bisection/Binary Chopping/Interval Halving/Bolzano bisection
+2. False Position/Regula Falsi falseposition
+3. Fixed Point fixedpoint
+4. Netwon-Raphson newtonraphson
+5. Netwon-Raphson 2 newtonraphson2
+6. Ralston and Rabinowitz ralstonrabinowitz
+7. Secant secant
+
+
+REFERENCES
+==========
+
+1. Steven C. Capra and Raymond P. Canale, Numerical Method for Engineers with
+ Personal Computer Application, McGraw-Hill, New York, USA, 1985.
+2. Abdul Munif and Aries Prastyoko H., Penguasaan dan Penggunaan Metode Numerik,
+ Edisi Kedua, Institut Teknologi Sepuluh November, Indonesia, 1995.
+3. mathworld.wolfram.com, http://mathworld.wolfram.com/topics/Root-Finding.html
+4. PHPMath, http://www.phpmath.com
+
+
+CONSTRIBUTION
+=============
+
+There is so many numerical method to find the root out there, constribution of
+resources, algorithms, modules (drivers), patches or related are very welcome.
+Just send it to firman@php.net
+
+
+CONSTRIBUTORS
+=============
+
+1. Jesus M. Castagnetto <jmcastagnetto@php.net>
+2. Lukasz Karapuda
+
+
+BUGS REPORT
+===========
+
+You can use PEAR Bugs System or send it directly via email to firman@php.net
@@ -0,0 +1,68 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
+
+// $Id$
+
+/**
+ * Bisection method usage example.
+ *
+ * @author Firman Wandayandi <firman@php.net>
+ * @package Math_Numerical_RootFinding
+ * @subpackage Examples
+ */
+
+/**
+ * Math_Numerical_RootFinding class
+ */
+require_once 'Math/Numerical/RootFinding.php';
+
+/**
+ * f(x) callback function.
+ *
+ * @param float $x Variable value.
+ *
+ * @return float
+ * @ignore
+ */
+function fx($x)
+{
+ return pow(M_E, -$x) - $x;
+}
+
+// Create new instance of Math_Numerical_RootFinding_Bisection.
+$mroot = Math_Numerical_RootFinding::factory('Bisection');
+if (PEAR::isError($mroot)) {
+ die($mroot->toString());
+}
+
+// Calculate the root using Bisection's method.
+$root = $mroot->compute('fx', 0, 1);
+if (PEAR::isError($root)) {
+ die($root->toString());
+}
+
+print "<h1>Root Finding::Bisection Method</h1>\n";
+$mroot->infoCompute();
+
+print "<h2>Case</h2>\n";
+print "f(x) = e<sup>-x</sup> - x<br />\n";
+
+print "<h3>Parameters</h3>\n";
+print "<b>Lower guest</b> = 0<br />\n";
+print "<b>Upper guest</b> = 1<br />\n";
+print "<b>True root</b> = 0,56714329...<br />\n";
+
+print "<h3>Result</h3>\n";
+print sprintf("<b>Iteration count</b> = %d<br />\n", $mroot->getIterationCount());
+print sprintf("<b>Root value</b> = %f<br />\n", $mroot->getRoot());
+print sprintf("<b>Estimate error</b> = %f<br />\n", $mroot->getEpsError());
+
+/*
+ * Local variables:
+ * mode: php
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+?>
@@ -0,0 +1,68 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
+
+// $Id$
+
+/**
+ * False Position method usage example.
+ *
+ * @author Firman Wandayandi <firman@php.net>
+ * @package Math_Numerical_RootFinding
+ * @subpackage Examples
+ */
+
+/**
+ * Math_Numerical_RootFinding class
+ */
+require_once 'Math/Numerical/RootFinding.php';
+
+/**
+ * f(x) callback function.
+ *
+ * @param float $x Variable value.
+ *
+ * @return float
+ * @ignore
+ */
+function fx($x)
+{
+ return pow(M_E, -$x) - $x;
+}
+
+// Create new instance of Math_Numerical_RootFinding_Falseposition.
+$mroot = Math_Numerical_RootFinding::factory('falseposition');
+if (PEAR::isError($mroot)) {
+ die($mroot->toString());
+}
+
+// Calculate the root using False Position's method.
+$root = $mroot->compute('fx', 0, 1);
+if (PEAR::isError($root)) {
+ die($root->toString());
+}
+
+print "<h1>Root Finding::False Position Method</h1>\n";
+$mroot->infoCompute();
+
+print "<h2>Case</h2>\n";
+print "f(x) = e<sup>-x</sup> - x<br />\n";
+
+print "<h3>Parameters</h3>\n";
+print "<b>First initial guest</b> = 0<br />\n";
+print "<b>Second initial guest</b> = 1<br />\n";
+print "<b>True root</b> = 0,56714329...<br />\n";
+
+print "<h3>Result</h3>\n";
+print sprintf("<b>Iteration count</b> = %d<br />\n", $mroot->getIterationCount());
+print sprintf("<b>Root value</b> = %f<br />\n", $mroot->getRoot());
+print sprintf("<b>Estimate error</b> = %f<br />\n", $mroot->getEpsError());
+
+/*
+ * Local variables:
+ * mode: php
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+?>
@@ -0,0 +1,67 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
+
+// $Id$
+
+/**
+ * Fixed Point method usage example.
+ *
+ * @author Firman Wandayandi <firman@php.net>
+ * @package Math_Numerical_RootFinding
+ * @subpackage Examples
+ */
+
+/**
+ * Math_Numerical_RootFinding class.
+ */
+require_once 'Math/Numerical/RootFinding.php';
+
+/**
+ * f(x) callback function.
+ *
+ * @param float $x Variable value.
+ *
+ * @return float
+ */
+function gx($x)
+{
+ return pow(M_E, -$x);
+}
+
+// Create new instance of Math_Numerical_RootFinding_Fixedpoint.
+$mroot = Math_Numerical_RootFinding::factory('fixedpoint');
+if (PEAR::isError($mroot)) {
+ die($mroot->toString());
+}
+
+// Calculate the root using Fixed Point's method.
+$root = $mroot->compute('gx', 0);
+if (PEAR::isError($root)) {
+ die($root->toString());
+}
+
+print "<h1>Root Finding::Fixed Point Method</h1>\n";
+$mroot->infoCompute();
+
+print "<h2>Case</h2>\n";
+print "f(x) = e<sup>-x</sup> - x<br />\n";
+print "g(x) = e<sup>-x</sup><br />\n";
+
+print "<h3>Parameters</h3>\n";
+print "<b>Initial guest</b> = 0<br />\n";
+print "<b>True root</b> = 0.56714329<br />\n";
+
+print "<h3>Result</h3>\n";
+print sprintf("<b>Iteration count</b> = %d<br />\n", $mroot->getIterationCount());
+print sprintf("<b>Root value</b> = %f<br />\n", $mroot->getRoot());
+print sprintf("<b>Estimate error</b> = %f<br />\n", $mroot->getEpsError());
+
+/*
+ * Local variables:
+ * mode: php
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+?>
@@ -0,0 +1,81 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
+
+// $Id$
+
+/**
+ * Newton-Raphson method usage example.
+ *
+ * @author Firman Wandayandi <firman@php.net>
+ * @package Math_Numerical_RootFinding
+ * @subpackage Examples
+ */
+
+/**
+ * Require Math_Numerical_RootFinding class.
+ */
+require_once 'Math/Numerical/RootFinding.php';
+
+/**
+ * f(x) callback function.
+ *
+ * @param float $x Variable value.
+ *
+ * @return float
+ * @ignore
+ */
+function fx($x)
+{
+ return pow(M_E, -$x) - $x;
+}
+
+/**
+ * f'(x) callback function.
+ *
+ * @param float $x Variable value.
+ *
+ * @return float
+ * @ignore
+ */
+function dx($x)
+{
+ return -pow(M_E, -$x) - 1;
+}
+
+// Create new instance of Math_Numerical_RootFinding_Newtonraphson.
+$mroot = Math_Numerical_RootFinding::factory('NewtonRaphson');
+if (PEAR::isError($mroot)) {
+ die($mroot->toString());
+}
+
+// Calculate the root using Newton-Raphson's method.
+$root = $mroot->compute('fx', 'dx', 0);
+if (PEAR::isError($root)) {
+ die($root->toString());
+}
+
+print "<h1>Root Finding::Newton-Raphson Method</h1>\n";
+$mroot->infoCompute();
+
+print "<h2>Case</h2>\n";
+print "f(x) = e<sup>-x</sup> - x<br />\n";
+print "f'(x) = -e<sup>-x</sup> - x<br />\n";
+
+print "<h3>Parameters</h3>\n";
+print "<b>Initial guest</b> = 0<br />\n";
+print "<b>True root</b> = 0,56714329...<br />\n";
+
+print "<h3>Result</h3>\n";
+print sprintf("<b>Iteration count</b> = %d<br />\n", $mroot->getIterationCount());
+print sprintf("<b>Root value</b> = %f<br />\n", $mroot->getRoot());
+print sprintf("<b>Estimate error</b> = %f<br />\n", $mroot->getEpsError());
+
+/*
+ * Local variables:
+ * mode: php
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+?>
Oops, something went wrong.

0 comments on commit 0714e36

Please sign in to comment.