[prev in list] [next in list] [prev in thread] [next in thread]
List: pear-cvs
Subject: [PEAR-CVS] cvs: pear /Math_Numerical_RootFinding/docs README.txt /Math_Numerical_RootFinding/docs/e
From: "Firman Wandayandi" <firman () php ! net>
Date: 2006-01-31 18:37:08
Message-ID: cvsfirman1138732628 () cvsserver
[Download RAW message or body]
firman Tue Jan 31 18:37:08 2006 UTC
Added files:
/pear/Math_Numerical_RootFinding/docs README.txt
/pear/Math_Numerical_RootFinding/docs/examples Bisection.php
FalsePosition.php
FixedPoint.php
Newton-Raphson.php
Newton-Raphson2.php
Ralston-Rabinowitz.php
Secant.php
Log:
Add docs directory and example files
["firman-20060131183708.txt" (text/plain)]
http://cvs.php.net/viewcvs.cgi/pear/Math_Numerical_RootFinding/docs/README.txt?view=markup&rev=1.1
Index: pear/Math_Numerical_RootFinding/docs/README.txt
+++ pear/Math_Numerical_RootFinding/docs/README.txt
================================
PEAR::Math_Numerical_RootFinding
================================
$Id: README.txt,v 1.1 2006/01/31 18:37:08 firman Exp $
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
http://cvs.php.net/viewcvs.cgi/pear/Math_Numerical_RootFinding/docs/examples/Bisection.php?view=markup&rev=1.1
Index: pear/Math_Numerical_RootFinding/docs/examples/Bisection.php
+++ pear/Math_Numerical_RootFinding/docs/examples/Bisection.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
// $Id: Bisection.php,v 1.1 2006/01/31 18:37:08 firman Exp $
/**
* 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:
*/
?>
http://cvs.php.net/viewcvs.cgi/pear/Math_Numerical_RootFinding/docs/examples/FalsePosition.php?view=markup&rev=1.1
Index: pear/Math_Numerical_RootFinding/docs/examples/FalsePosition.php
+++ pear/Math_Numerical_RootFinding/docs/examples/FalsePosition.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
// $Id: FalsePosition.php,v 1.1 2006/01/31 18:37:08 firman Exp $
/**
* 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:
*/
?>
http://cvs.php.net/viewcvs.cgi/pear/Math_Numerical_RootFinding/docs/examples/FixedPoint.php?view=markup&rev=1.1
Index: pear/Math_Numerical_RootFinding/docs/examples/FixedPoint.php
+++ pear/Math_Numerical_RootFinding/docs/examples/FixedPoint.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
// $Id: FixedPoint.php,v 1.1 2006/01/31 18:37:08 firman Exp $
/**
* 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:
*/
?>
http://cvs.php.net/viewcvs.cgi/pear/Math_Numerical_RootFinding/docs/examples/Newton-Raphson.php?view=markup&rev=1.1
Index: pear/Math_Numerical_RootFinding/docs/examples/Newton-Raphson.php
+++ pear/Math_Numerical_RootFinding/docs/examples/Newton-Raphson.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
// $Id: Newton-Raphson.php,v 1.1 2006/01/31 18:37:08 firman Exp $
/**
* 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:
*/
?>
http://cvs.php.net/viewcvs.cgi/pear/Math_Numerical_RootFinding/docs/examples/Newton-Raphson2.php?view=markup&rev=1.1
Index: pear/Math_Numerical_RootFinding/docs/examples/Newton-Raphson2.php
+++ pear/Math_Numerical_RootFinding/docs/examples/Newton-Raphson2.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
// $Id: Newton-Raphson2.php,v 1.1 2006/01/31 18:37:08 firman Exp $
/**
* Newton-Raphson 2 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($x, 3) - (5 * pow($x,2)) + (7 * $x) - 3;
}
/**
* f'(x) callback function.
*
* @param float $x Variable value.
*
* @return float
*/
function d1x($x)
{
return 3 * pow($x, 2) - (10 * $x) + 7;
}
/**
* f''(x) callback function.
*
* @param float $x Variable value.
*
* @return float
*/
function d2x($x)
{
return 6 * $x - 10;
}
// Create new instance of Math_Numerical_RootFinding_Newtonraphson2.
$mroot = Math_Numerical_RootFinding::factory('NewtonRaphson2');
if (PEAR::isError($mroot)) {
die($mroot->toString());
}
// Calculate the root using Newton-Raphson 2 method.
$root = $mroot->compute('fx', 'd1x', 'd2x', 0);
if (PEAR::isError($root)) {
die($root->toString());
}
print "<h1>Root Finding::Newton-Raphson 2 Method</h1>\n";
$mroot->infoCompute();
print "<h2>Case</h2>\n";
print "f(x) = x<sup>3</sup> - 5x<sup>2</sup> + 7x - 3<br />\n";
print "f'(x) = 3x<sup>2</sup> - 10x + 7<br />\n";
print "f''(x) = 6x - 10<br />\n";
print "<h3>Parameters</h3>\n";
print "<b>Initial guest</b> = 0<br />\n";
print "<b>True root</b> = 1<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:
*/
?>
http://cvs.php.net/viewcvs.cgi/pear/Math_Numerical_RootFinding/docs/examples/Ralston-Rabinowitz.php?view=markup&rev=1.1
Index: pear/Math_Numerical_RootFinding/docs/examples/Ralston-Rabinowitz.php
+++ pear/Math_Numerical_RootFinding/docs/examples/Ralston-Rabinowitz.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
// $Id: Ralston-Rabinowitz.php,v 1.1 2006/01/31 18:37:08 firman Exp $
/**
* Ralston and Rabinowitz 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($x, 3) - (5 * pow($x,2)) + (7 * $x) - 3;
}
/**
* f'(x) callback function.
*
* @param float $x Variable value.
*
* @return float
* @ignore
*/
function dx($x)
{
return 3 * pow($x, 2) - (10 * $x) + 7;
}
// Create new instance of Math_Numerical_RootFinding_Ralstonrabinowitz.
$mroot = Math_Numerical_RootFinding::factory('RalstonRabinowitz');
if (PEAR::isError($mroot)) {
die($mroot->toString());
}
// Calculate the root using Ralston and Rabinowitz's method.
$root = $mroot->compute('fx', 'dx', 0, 4);
if (PEAR::isError($root)) {
die($root->toString());
}
print "<h1>Root Finding::Ralston and Rabinowitz Method</h1>\n";
$mroot->infoCompute();
print "<h2>Case</h2>\n";
print "f(x) = x<sup>3</sup> - 5x<sup>2</sup> + 7x - 3<br />\n";
print "f'(x) = 3x<sup>2</sup> - 10x + 7<br />\n";
print "<h3>Parameters</h3>\n";
print "<b>First initial guest</b> (<u>\$xR0</u>) = 0<br />\n";
print "<b>Second initial guest</b> (<u>\$xR1</u>) = 4<br />\n";
print "<b>True root</b> = 1<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:
*/
?>
http://cvs.php.net/viewcvs.cgi/pear/Math_Numerical_RootFinding/docs/examples/Secant.php?view=markup&rev=1.1
Index: pear/Math_Numerical_RootFinding/docs/examples/Secant.php
+++ pear/Math_Numerical_RootFinding/docs/examples/Secant.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker */
// $Id: Secant.php,v 1.1 2006/01/31 18:37:08 firman Exp $
/**
* Secant 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_Secant.
$mroot = Math_Numerical_RootFinding::factory('Secant');
if (PEAR::isError($mroot)) {
die($mroot->toString());
}
// Calculate the root using Secant's method.
$root = $mroot->compute('fx', 0, 1);
if (PEAR::isError($root)) {
die($root->toString());
}
print "<h1>Root Finding::Secant Method</h1>\n";
$mroot->infoCompute();
print "<h2>Case</h2>\n";
print "<b>Case:</b><br />\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:
*/
?>
--
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic