Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Remove some driver files

  • Loading branch information...
commit 20cc3523a27ed320021b417db79444ed30833b89 1 parent 74f1c9d
authored January 30, 2006
221  Math/Numerical/RootFinding/Falseposition.php
... ...
@@ -1,221 +0,0 @@
1  
-<?php
2  
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3  
-// {{{ Header
4  
-// +----------------------------------------------------------------------+
5  
-// | PEAR, the PHP Extension and Application Repository                   |
6  
-// +----------------------------------------------------------------------+
7  
-// | PHP version 4                                                        |
8  
-// +----------------------------------------------------------------------+
9  
-// | Copyright (C) 2004  Firman Wandayandi                                |
10  
-// | All rights reserved.                                                 |
11  
-// +----------------------------------------------------------------------+
12  
-// | Redistribution and use in source and binary forms, with or without   |
13  
-// | modification, are permitted provided that the following conditions   |
14  
-// | are met:                                                             |
15  
-// |                                                                      |
16  
-// |   Redistributions of source code must retain the above copyright     |
17  
-// |   notice, this list of conditions and the following disclaimer.      |
18  
-// |                                                                      |
19  
-// |   Redistributions in binary form must reproduce the above            |
20  
-// |   copyright notice, this list of conditions and the following        |
21  
-// |   disclaimer in the documentation and/or other materials provided    |
22  
-// |   with the distribution.                                             |
23  
-// |                                                                      |
24  
-// |   Neither the name of Firman Wandayandi nor the names of             |
25  
-// |   contributors may be used to endorse or promote products derived    |
26  
-// |   from this software without specific prior written permission.      |
27  
-// |                                                                      |
28  
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29  
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30  
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31  
-// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE       |
32  
-// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
33  
-// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34  
-// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
35  
-// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
36  
-// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
37  
-// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
38  
-// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
39  
-// | POSSIBILITY OF SUCH DAMAGE.                                          |
40  
-// +----------------------------------------------------------------------+
41  
-// | Authors: Firman Wandayandi <firman@php.net>                          |
42  
-// +----------------------------------------------------------------------+
43  
-// }}}
44  
-// $Id$
45  
-
46  
-/**
47  
- * Driver file contains Math_Numerical_RootFinding_Bisection class to provide
48  
- * False Position/Regula Falsi method root finding calculation.
49  
- *
50  
- * @author Firman Wandayandi <firman@php.net>
51  
- * @package Math_Numerical_RootFinding
52  
- * @subpackage Methods
53  
- * @category Math
54  
- * @license http://www.opensource.org/licenses/bsd-license.php
55  
- *          BSD License
56  
- */
57  
-
58  
-// {{{ Dependencies
59  
-
60  
-/**
61  
- * Load Math_Numerical_RootFinding_Common as base class.
62  
- */
63  
-require_once 'Math/Numerical/RootFinding/Common.php';
64  
-
65  
-// }}}
66  
-
67  
-/**
68  
- * False Position/Regula Falsi method class.
69  
- *
70  
- * @author Firman Wandayandi <firman@php.net>
71  
- * @package Math_Numerical_RootFinding
72  
- * @subpackage Methods
73  
- */
74  
-class Math_Numerical_RootFinding_Falseposition
75  
-extends Math_Numerical_RootFinding_Common
76  
-{
77  
-    // {{{ Constructor
78  
-
79  
-    /**
80  
-     * PHP4 compatible constructor.
81  
-     *
82  
-     * @param array $options (optional) Options.
83  
-     *
84  
-     * @access public
85  
-     */
86  
-    function Math_Numerical_RootFinding_Falseposition($options = null)
87  
-    {
88  
-        parent::__construct($options);
89  
-    }
90  
-
91  
-    // }}}
92  
-    // {{{ infoCompute()
93  
-
94  
-    /**
95  
-     * Print out parameters description for compute() function.
96  
-     *
97  
-     * @access public
98  
-     */
99  
-    function infoCompute()
100  
-    {
101  
-        print "<h2>False Position::compute()</h2>\n" .
102  
-
103  
-              "<em>float</em> | <em>PEAR_Error</em> ".
104  
-              "<strong>compute</strong>(<u>\$fxFunction</u>, <u>\$xL</u>, ".
105  
-              "<u>\$xU</u>)<br />\n" .
106  
-
107  
-              "<h3>Description</h3>\n".
108  
-
109  
-              "<em>callback</em> <u>\$fxFunction</u> Callback f(x) equation ".
110  
-              "function or object/method tuple.<br>\n" .
111  
-
112  
-              "<em>float</em> <u>\$xL</u> Lower guess.<br>\n" .
113  
-
114  
-              "<em>float</em> <u>\$xU</u> Upper guess.<br>\n";
115  
-    }
116  
-
117  
-    // }}}
118  
-    // {{{ compute()
119  
-
120  
-    /**
121  
-     * False Position/Regula Falsi method.
122  
-     *
123  
-     * @param callback $fxFunction Callback f(x) equation function or
124  
-     *                             object/method tuple.
125  
-     * @param float $xL Lower guess.
126  
-     * @param float $xU Upper guess.
127  
-     *
128  
-     * @return float|PEAR_Error root value on success or PEAR_Error on failure.
129  
-     * @access public
130  
-     * @see Math_Numerical_RootFinding_Common::validateEqFunction()
131  
-     * @see Math_Numerical_RootFinding_Common::getEqResult()
132  
-     * @see Math_Numerical_RootFinding_Bisection::compute()
133  
-     */
134  
-    function compute($fxFunction, $xL, $xU)
135  
-    {
136  
-        // Validate f(x) equation function.
137  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($fxFunction);
138  
-        if (PEAR::isError($err)) {
139  
-            return $err;
140  
-        }
141  
-
142  
-        // Sets maximum iteration and tolerance from options.
143  
-        $maxIteration = $this->options['max_iteration'];
144  
-        $errTolerance = $this->options['err_tolerance'];
145  
-
146  
-        // Calculate first approximation $xR (False Position's formula).
147  
-        $fxL = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xL);
148  
-        $fxU = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xU);
149  
-        if ($fxL - $fxU == 0) {
150  
-            return PEAR::raiseError('Iteration skipped, division by zero');
151  
-        }
152  
-        $xR = $xU - (($fxU * ($xL - $xU)) / ($fxL - $fxU));
153  
-
154  
-        // Sets variable for saving errors during iteration, for divergent
155  
-        // detection.
156  
-        $epsErrors = array();
157  
-
158  
-        for ($i = 0; $i < $maxIteration; $i++) {
159  
-            // Calculate f(xr), where: xr = $xR
160  
-            $fxR = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xR);
161  
-
162  
-            if ($fxL * $fxR < 0) { // Root is at first subinterval.
163  
-                $xU = $xR;
164  
-            } elseif ($fxL * $fxR > 0) { // Root is at second subinterval.
165  
-                $xL = $xR;
166  
-            } elseif ($fxL * $fxR == 0) { // $xR is the exact root.
167  
-                $this->root = $xR;
168  
-                break;
169  
-            }
170  
-
171  
-            // Avoid division by zero.
172  
-            if ($fxL - $fxU == 0) {
173  
-                return PEAR::raiseError('Iteration skipped, division by zero');
174  
-            }
175  
-
176  
-            // Compute new approximation.
177  
-            $xN = $xU - (($fxU * ($xL - $xU)) / ($fxL - $fxU));
178  
-
179  
-            // Compute approximation error.
180  
-            $this->epsError = abs(($xN - $xR) / $xN);
181  
-            $epsErrors[] = $this->epsError;
182  
-
183  
-            // Detect for divergent rows.
184  
-            if ($this->isDivergentRows($epsErrors) &&
185  
-                $this->options['divergent_skip'])
186  
-            {
187  
-                return PEAR::raiseError('Iteration skipped, divergent rows detected');
188  
-                break;
189  
-            }
190  
-
191  
-            // Check for error tolerance, if lower than or equal with
192  
-            // $errTolerance it is the root.
193  
-            if ($this->epsError <= $errTolerance) {
194  
-                $this->root = $xN;
195  
-                break;
196  
-            }
197  
-
198  
-            // Calculate f(xl), where xl = $xL.
199  
-            $fxL = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xL);
200  
-            // Calculate f(xu), where xu = $xU.
201  
-            $fxU = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xU);
202  
-
203  
-            // Switch xn -> xr, where xn = $xN and xr = $xR.
204  
-            $xR = $xN;
205  
-        }
206  
-        $this->iterationCount = $i;
207  
-        return $this->root;
208  
-    }
209  
-
210  
-    // }}}
211  
-}
212  
-
213  
-/*
214  
- * Local variables:
215  
- * mode: php
216  
- * tab-width: 4
217  
- * c-basic-offset: 4
218  
- * c-hanging-comment-ender-p: nil
219  
- * End:
220  
- */
221  
-?>
196  Math/Numerical/RootFinding/Fixedpoint.php
... ...
@@ -1,196 +0,0 @@
1  
-<?php
2  
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3  
-// {{{ Header
4  
-// +----------------------------------------------------------------------+
5  
-// | PEAR, the PHP Extension and Application Repository                   |
6  
-// +----------------------------------------------------------------------+
7  
-// | PHP version 4                                                        |
8  
-// +----------------------------------------------------------------------+
9  
-// | Copyright (C) 2004  Firman Wandayandi                                |
10  
-// | All rights reserved.                                                 |
11  
-// +----------------------------------------------------------------------+
12  
-// | Redistribution and use in source and binary forms, with or without   |
13  
-// | modification, are permitted provided that the following conditions   |
14  
-// | are met:                                                             |
15  
-// |                                                                      |
16  
-// |   Redistributions of source code must retain the above copyright     |
17  
-// |   notice, this list of conditions and the following disclaimer.      |
18  
-// |                                                                      |
19  
-// |   Redistributions in binary form must reproduce the above            |
20  
-// |   copyright notice, this list of conditions and the following        |
21  
-// |   disclaimer in the documentation and/or other materials provided    |
22  
-// |   with the distribution.                                             |
23  
-// |                                                                      |
24  
-// |   Neither the name of Firman Wandayandi nor the names of             |
25  
-// |   contributors may be used to endorse or promote products derived    |
26  
-// |   from this software without specific prior written permission.      |
27  
-// |                                                                      |
28  
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29  
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30  
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31  
-// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE       |
32  
-// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
33  
-// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34  
-// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
35  
-// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
36  
-// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
37  
-// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
38  
-// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
39  
-// | POSSIBILITY OF SUCH DAMAGE.                                          |
40  
-// +----------------------------------------------------------------------+
41  
-// | Authors: Firman Wandayandi <firman@php.net>                          |
42  
-// +----------------------------------------------------------------------+
43  
-// }}}
44  
-// $Id$
45  
-
46  
-/**
47  
- * Driver file contains Math_Numerical_RootFinding_Bisection class to provide
48  
- * Fixed Point method root finding calculation.
49  
- *
50  
- * @author Firman Wandayandi <firman@php.net>
51  
- * @package Math_Numerical_RootFinding
52  
- * @subpackage Methods
53  
- * @category Math
54  
- * @license http://www.opensource.org/licenses/bsd-license.php
55  
- *          BSD License
56  
- */
57  
-
58  
-// {{{ Dependencies
59  
-
60  
-/**
61  
- * Load Math_Numerical_RootFinding_Common as base class.
62  
- */
63  
-require_once 'Math/Numerical/RootFinding/Common.php';
64  
-
65  
-// }}}
66  
-
67  
-/**
68  
- * Fixed Point method class.
69  
- *
70  
- * @author Firman Wandayandi <firman@php.net>
71  
- * @package Math_Numerical_RootFinding
72  
- * @subpackage Methods
73  
- */
74  
-class Math_Numerical_RootFinding_Fixedpoint
75  
-extends Math_Numerical_RootFinding_Common
76  
-{
77  
-    // {{{ Constructor
78  
-
79  
-    /**
80  
-     * PHP4 compatible constructor.
81  
-     *
82  
-     * @param array $options (optional) Options.
83  
-     *
84  
-     * @access public
85  
-     */
86  
-    function Math_Numerical_RootFinding_Fixedpoint($options = null)
87  
-    {
88  
-        parent::__construct($options);
89  
-    }
90  
-
91  
-    // }}}
92  
-    // {{{ infoCompute()
93  
-
94  
-    /**
95  
-     * Print out parameters description for compute() function.
96  
-     *
97  
-     * @access public
98  
-     */
99  
-    function infoCompute()
100  
-    {
101  
-        print "<h2>Fixed Point::compute()</h2>\n" .
102  
-
103  
-              "<em>float</em> | <em>PEAR_Error</em> ".
104  
-              "<strong>compute</strong>(<u>\$gxFunction</u>, <u>\$xR</u>)<br />\n" .
105  
-
106  
-              "<h3>Description</h3>\n" .
107  
-
108  
-              "<em>callback</em> <u>\$gxFunction</u> Callback g(x) " .
109  
-              "equation (the modification of f(x), which g(x) = x) " .
110  
-              "function or object/method tuple.<br>\n" .
111  
-
112  
-              "<em>float</em> <u>\$xR</u> Initial guess.<br>\n";
113  
-    }
114  
-
115  
-    // }}}
116  
-    // {{{ compute()
117  
-
118  
-    /**
119  
-     * Fixed Point method.
120  
-     *
121  
-     * This method using g(x) (the modification of f(x), which g(x) = x).
122  
-     *
123  
-     * @param callback $gxFunction Callback g(x) equation function or
124  
-     *                             object/method tuple.
125  
-     * @param float $xR Initial guess.
126  
-     *
127  
-     * @return float|PEAR_Error root value on success or PEAR_Error on failure.
128  
-     * @access public
129  
-     * @see Math_Numerical_RootFinding_Common::validateEqFunction()
130  
-     * @see Math_Numerical_RootFinding_Common::getEqResult()
131  
-     * @see Math_Numerical_RootFinding_Common::isDivergentRow()
132  
-     */
133  
-    function compute($gxFunction, $xR)
134  
-    {
135  
-        // Validate g(x) equation function.
136  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($gxFunction);
137  
-        if (PEAR::isError($err)) {
138  
-            return $err;
139  
-        }
140  
-
141  
-        // Sets maximum iteration and tolerance from options.
142  
-        $maxIteration = $this->options['max_iteration'];
143  
-        $errTolerance = $this->options['err_tolerance'];
144  
-
145  
-        // Sets variable for saving errors during iteration, for divergent
146  
-        // detection.
147  
-        $epsErrors = array();
148  
-
149  
-        for($i = 0; $i < $maxIteration; $i++) {
150  
-            // Calculate g(x[i]), where x[i] = $xR (Fixed Point's formula).
151  
-            $xN = Math_Numerical_RootFinding_Common::getEqResult($gxFunction, $xR);
152  
-
153  
-            // xR is the root.
154  
-            if ($xN == 0) {
155  
-                $this->root = $xR;
156  
-                break;
157  
-            }
158  
-
159  
-            // Compute error.
160  
-            $this->epsError = abs(($xN - $xR) / $xN);
161  
-            $epsErrors[] = $this->epsError;
162  
-
163  
-            // Detect for divergent rows.
164  
-            if ($this->isDivergentRows($epsErrors) &&
165  
-                $this->options['divergent_skip'])
166  
-            {
167  
-                return PEAR::raiseError('Iteration skipped, divergent rows detected');
168  
-                break;
169  
-            }
170  
-
171  
-            // Check for error tolerance, if lower than or equal with
172  
-            // $errTolerance it is the root.
173  
-            if ($this->epsError <= $errTolerance) {
174  
-                $this->root = $xR;
175  
-                break;
176  
-            }
177  
-
178  
-            // Switch x[i+1] -> x[i], where: x[i] = $xR and x[i+1] = $xN.
179  
-            $xR = $xN;
180  
-        }
181  
-        $this->iterationCount = $i;
182  
-        return $this->root;
183  
-    }
184  
-
185  
-    // }}}
186  
-}
187  
-
188  
-/*
189  
- * Local variables:
190  
- * mode: php
191  
- * tab-width: 4
192  
- * c-basic-offset: 4
193  
- * c-hanging-comment-ender-p: nil
194  
- * End:
195  
- */
196  
-?>
218  Math/Numerical/RootFinding/Newtonraphson.php
... ...
@@ -1,218 +0,0 @@
1  
-<?php
2  
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3  
-// {{{ Header
4  
-// +----------------------------------------------------------------------+
5  
-// | PEAR, the PHP Extension and Application Repository                   |
6  
-// +----------------------------------------------------------------------+
7  
-// | PHP version 4                                                        |
8  
-// +----------------------------------------------------------------------+
9  
-// | Copyright (C) 2004  Firman Wandayandi                                |
10  
-// | All rights reserved.                                                 |
11  
-// +----------------------------------------------------------------------+
12  
-// | Redistribution and use in source and binary forms, with or without   |
13  
-// | modification, are permitted provided that the following conditions   |
14  
-// | are met:                                                             |
15  
-// |                                                                      |
16  
-// |   Redistributions of source code must retain the above copyright     |
17  
-// |   notice, this list of conditions and the following disclaimer.      |
18  
-// |                                                                      |
19  
-// |   Redistributions in binary form must reproduce the above            |
20  
-// |   copyright notice, this list of conditions and the following        |
21  
-// |   disclaimer in the documentation and/or other materials provided    |
22  
-// |   with the distribution.                                             |
23  
-// |                                                                      |
24  
-// |   Neither the name of Firman Wandayandi nor the names of             |
25  
-// |   contributors may be used to endorse or promote products derived    |
26  
-// |   from this software without specific prior written permission.      |
27  
-// |                                                                      |
28  
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29  
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30  
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31  
-// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE       |
32  
-// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
33  
-// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34  
-// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
35  
-// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
36  
-// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
37  
-// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
38  
-// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
39  
-// | POSSIBILITY OF SUCH DAMAGE.                                          |
40  
-// +----------------------------------------------------------------------+
41  
-// | Authors: Firman Wandayandi <firman@php.net>                          |
42  
-// +----------------------------------------------------------------------+
43  
-// }}}
44  
-// $Id$
45  
-
46  
-/**
47  
- * Driver file contains Math_Numerical_RootFinding_Bisection class to provide
48  
- * Newton-Raphson method root finding calculation.
49  
- *
50  
- * @author Firman Wandayandi <firman@php.net>
51  
- * @package Math_Numerical_RootFinding
52  
- * @subpackage Methods
53  
- * @category Math
54  
- * @license http://www.opensource.org/licenses/bsd-license.php
55  
- *          BSD License
56  
- */
57  
-
58  
-// {{{ Dependencies
59  
-
60  
-/**
61  
- * Load Math_Numerical_RootFinding_Common as base class.
62  
- */
63  
-require_once 'Math/Numerical/RootFinding/Common.php';
64  
-
65  
-// }}}
66  
-
67  
-/**
68  
- * Newton-Raphson method class.
69  
- *
70  
- * @author Firman Wandayandi <firman@php.net>
71  
- * @package Math_Numerical_RootFinding
72  
- * @subpackage Methods
73  
- */
74  
-class Math_Numerical_RootFinding_Newtonraphson
75  
-extends Math_Numerical_RootFinding_Common
76  
-{
77  
-    // {{{ Constructor
78  
-
79  
-    /**
80  
-     * PHP4 compatible constructor.
81  
-     *
82  
-     * @param array $options Options.
83  
-     *
84  
-     * @access public
85  
-     */
86  
-    function Math_Numerical_RootFinding_Newtonraphson($options = null)
87  
-    {
88  
-        parent::__construct($options);
89  
-    }
90  
-
91  
-    // }}}
92  
-    // {{{ infoCompute()
93  
-
94  
-    /**
95  
-     * Print out parameters description for compute() function.
96  
-     *
97  
-     * @access public
98  
-     */
99  
-    function infoCompute()
100  
-    {
101  
-        print "<h2>False Position::compute()</h2>\n" .
102  
-
103  
-              "<em>float</em> | <em>PEAR_Error</em> " .
104  
-              "<strong>compute</strong>(<u>\$fxFunction</u>, " .
105  
-
106  
-              "<u>\$dfxFunction</u>, <u>\$xR</u>)<br />\n" .
107  
-
108  
-              "<h3>Description</h3>\n" .
109  
-
110  
-              "<em>callback</em> <u>\$fxFunction</u> Callback f(x) equation " .
111  
-              "function or object/method tuple.<br>\n" .
112  
-
113  
-              "<em>callback</em> <u>\$dfxFunction</u> Callback f'(x) equation " .
114  
-              "function or object/method tuple.<br>\n" .
115  
-
116  
-              "<em>float</em> <u>\$xR</u> Initial guess.<br>\n";
117  
-    }
118  
-
119  
-    // }}}
120  
-    // {{{ compute()
121  
-
122  
-    /**
123  
-     * Netwon-Raphson method.
124  
-     *
125  
-     * @param callback $fxFunction Callback f(x) equation function or
126  
-     *                             object/method tuple.
127  
-     * @param callback $dfxFunction Callback f'(x) equation function or
128  
-     *                              object/method tuple.
129  
-     * @param float $xR Initial guess.
130  
-     *
131  
-     * @return float|PEAR_Error Root value on success or PEAR_Error on
132  
-     *                          failure.
133  
-     * @access public
134  
-     * @see Math_Numerical_RootFinding_Common::validateEqFunction()
135  
-     * @see Math_Numerical_RootFinding_Common::getEqResult()
136  
-     * @see Math_Numerical_RootFinding_Common::isDivergentRow()
137  
-     * @see Math_Numerical_RootFinding_Newtonraphson2::compute()
138  
-     */
139  
-    function compute($fxFunction, $dfxFunction, $xR) {
140  
-        // evaluate f(x) equation function before begin anything
141  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($fxFunction);
142  
-        if (PEAR::isError($err)) {
143  
-            return $err;
144  
-        }
145  
-
146  
-        // evaluate df(x) equation function before begin anything
147  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($dfxFunction);
148  
-        if (PEAR::isError($err)) {
149  
-            return $err;
150  
-        }
151  
-
152  
-        // Sets maximum iteration and tolerance from options.
153  
-        $maxIteration = $this->options['max_iteration'];
154  
-        $errTolerance = $this->options['err_tolerance'];
155  
-
156  
-        // Sets variable for saving errors during iteration, for divergent
157  
-        // detection.
158  
-        $epsErrors = array();
159  
-
160  
-        for ($i = 1; $i < $maxIteration; $i++) {
161  
-            // Calculate f(x[i]), where: x[i] = $xR.
162  
-            $fxR = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xR);
163  
-
164  
-            // Calculate f'(x[i]), where: x[i] = $xR.
165  
-            $dxR = Math_Numerical_RootFinding_Common::getEqResult($dfxFunction, $xR);
166  
-
167  
-            // Avoid division by zero.
168  
-            if ($dxR == 0) {
169  
-                return PEAR::raiseError('Iteration skipped, division by zero');
170  
-            }
171  
-
172  
-            // Newton-Raphson's formula.
173  
-            $xN = $xR - ($fxR / $dxR);
174  
-
175  
-            // xR is the root.
176  
-            if ($xN == 0) {
177  
-                $this->root = $xR;
178  
-                break;
179  
-            }
180  
-
181  
-            // Compute error.
182  
-            $this->epsError = abs(($xN - $xR) / $xN);
183  
-            $epsErrors[] = $this->epsError;
184  
-
185  
-            // Detect for divergent rows.
186  
-            if ($this->isDivergentRows($epsErrors) &&
187  
-                $this->options['divergent_skip'])
188  
-            {
189  
-                return PEAR::raiseError('Iteration skipped, divergent rows detected');
190  
-                break;
191  
-            }
192  
-
193  
-            // Check for error tolerance, if lower than or equal with
194  
-            // $errTolerance it is the root.
195  
-            if ($this->epsError <= $errTolerance) {
196  
-                $this->root = $xR;
197  
-                break;
198  
-            }
199  
-
200  
-            // Switch x[i+1] -> x[i], where: x[i] = $xR and x[i+1] = $xN.
201  
-            $xR = $xN;
202  
-        }
203  
-        $this->iterationCount = $i;
204  
-        return $this->root;
205  
-    }
206  
-
207  
-    // }}}
208  
-}
209  
-
210  
-/*
211  
- * Local variables:
212  
- * mode: php
213  
- * tab-width: 4
214  
- * c-basic-offset: 4
215  
- * c-hanging-comment-ender-p: nil
216  
- * End:
217  
- */
218  
-?>
231  Math/Numerical/RootFinding/Newtonraphson2.php
... ...
@@ -1,231 +0,0 @@
1  
-<?php
2  
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3  
-// {{{ Header
4  
-// +----------------------------------------------------------------------+
5  
-// | PEAR, the PHP Extension and Application Repository                   |
6  
-// +----------------------------------------------------------------------+
7  
-// | PHP version 4                                                        |
8  
-// +----------------------------------------------------------------------+
9  
-// | Copyright (C) 2004  Firman Wandayandi                                |
10  
-// | All rights reserved.                                                 |
11  
-// +----------------------------------------------------------------------+
12  
-// | Redistribution and use in source and binary forms, with or without   |
13  
-// | modification, are permitted provided that the following conditions   |
14  
-// | are met:                                                             |
15  
-// |                                                                      |
16  
-// |   Redistributions of source code must retain the above copyright     |
17  
-// |   notice, this list of conditions and the following disclaimer.      |
18  
-// |                                                                      |
19  
-// |   Redistributions in binary form must reproduce the above            |
20  
-// |   copyright notice, this list of conditions and the following        |
21  
-// |   disclaimer in the documentation and/or other materials provided    |
22  
-// |   with the distribution.                                             |
23  
-// |                                                                      |
24  
-// |   Neither the name of Firman Wandayandi nor the names of             |
25  
-// |   contributors may be used to endorse or promote products derived    |
26  
-// |   from this software without specific prior written permission.      |
27  
-// |                                                                      |
28  
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29  
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30  
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31  
-// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE       |
32  
-// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
33  
-// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34  
-// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
35  
-// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
36  
-// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
37  
-// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
38  
-// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
39  
-// | POSSIBILITY OF SUCH DAMAGE.                                          |
40  
-// +----------------------------------------------------------------------+
41  
-// | Authors: Firman Wandayandi <firman@php.net>                          |
42  
-// +----------------------------------------------------------------------+
43  
-// }}}
44  
-// $Id$
45  
-
46  
-/**
47  
- * Driver file contains Math_Numerical_RootFinding_Bisection class to provide
48  
- * Newton-Raphson 2 method root finding calculation.
49  
- *
50  
- * @author Firman Wandayandi <firman@php.net>
51  
- * @package Math_Numerical_RootFinding
52  
- * @subpackage Methods
53  
- * @category Math
54  
- * @license http://www.opensource.org/licenses/bsd-license.php
55  
- *          BSD License
56  
- */
57  
-
58  
-// {{{ Dependencies
59  
-
60  
-/**
61  
- * Load Math_Numerical_RootFinding_Common as base class.
62  
- */
63  
-require_once 'Math/Numerical/RootFinding/Common.php';
64  
-
65  
-// }}}
66  
-
67  
-/**
68  
- * Newton-Raphson 2 method class.
69  
- *
70  
- * @author Firman Wandayandi <firman@php.net>
71  
- * @package Math_Numerical_RootFinding
72  
- * @subpackage Methods
73  
- */
74  
-class Math_Numerical_RootFinding_Newtonraphson2
75  
-extends Math_Numerical_RootFinding_Common
76  
-{
77  
-    // {{{ Constructor
78  
-
79  
-    /**
80  
-     * Constructor.
81  
-     *
82  
-     * @param array $options Options.
83  
-     *
84  
-     * @access public
85  
-     */
86  
-    function Math_Numerical_RootFinding_Newtonraphson2($options = null)
87  
-    {
88  
-        parent::__construct($options);
89  
-    }
90  
-
91  
-    // }}}
92  
-    // {{{ infoCompute()
93  
-
94  
-    /**
95  
-     * Print out parameters description for compute() function.
96  
-     *
97  
-     * @access public
98  
-     */
99  
-    function infoCompute()
100  
-    {
101  
-        print "<h2>False Position::compute()</h2>\n" .
102  
-
103  
-              "<em>float</em> | <em>PEAR_Error</em> " .
104  
-              "<strong>compute</strong>(<u>\$fxFunction</u>, " .
105  
-              "<u>\$dfx1Function</u>, <u>\$dfx2Function</u>, " .
106  
-              "<u>\$xR</u>)<br />\n" .
107  
-
108  
-              "<h3>Description</h3>\n" .
109  
-              "<em>callback</em> <u>\$fxFunction</u> Callback f(x) equation " .
110  
-              "function or object/method tuple.<br>\n" .
111  
-
112  
-              "<em>callback</em> <u>\$dfx1Function</u> Callback f'(x) " .
113  
-              "equation function or object/method tuple.<br>\n" .
114  
-
115  
-              "<em>callback</em> <u>\$dfx2Function</u> Callback f''(x) " .
116  
-              "equation function or object/method tuple.<br>\n" .
117  
-
118  
-              "<em>float</em> <u>\$xR</u> Initial guess.<br>\n";
119  
-    }
120  
-
121  
-    // }}}
122  
-    // {{{ compute()
123  
-
124  
-    /**
125  
-     * Newton-Raphson method for calculate double root (twin root).
126  
-     *
127  
-     * @param callback $fxFunction Callback f(x) equation function or
128  
-     *                             object/method tuple.
129  
-     * @param callback $dfx1Function Callback f'(x) equation function or
130  
-     *                              object/method tuple.
131  
-     * @param callback $dfx2Function Callback f''(x) equation function or
132  
-     *                              object/method tuple.
133  
-     * @param float $xR Initial guess.
134  
-     *
135  
-     * @return float|PEAR_Error Root value on success or PEAR_Error on failure.
136  
-     * @access public
137  
-     * @see Math_Numerical_RootFinding_Common::validateEqFunction()
138  
-     * @see Math_Numerical_RootFinding_Common::getEqResult()
139  
-     * @see Math_Numerical_RootFinding_Common::isDivergentRow()
140  
-     * @see Math_Numerical_RootFinding_Newtonraphson::compute()
141  
-     */
142  
-    function compute($fxFunction, $dfx1Function, $dfx2Function, $xR)
143  
-    {
144  
-        // Validate f(x) equation function.
145  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($fxFunction);
146  
-        if (PEAR::isError($err)) {
147  
-            return $err;
148  
-        }
149  
-
150  
-        // Validate f'(x) equation function.
151  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($dfx1Function);
152  
-        if (PEAR::isError($err)) {
153  
-            return $err;
154  
-        }
155  
-
156  
-        // Validate f''(x) equation function.
157  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($dfx2Function);
158  
-        if (PEAR::isError($err)) {
159  
-            return $err;
160  
-        }
161  
-
162  
-        // Sets maximum iteration and tolerance from options.
163  
-        $maxIteration = $this->options['max_iteration'];
164  
-        $errTolerance = $this->options['err_tolerance'];
165  
-
166  
-        // Sets variable for saving errors during iteration, for divergent
167  
-        // detection.
168  
-        $epsErrors = array();
169  
-
170  
-        for ($i = 1; $i < $maxIteration; $i++) {
171  
-            // Calculate f(x[i]), where: x[i] = $xR.
172  
-            $fxR = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xR);
173  
-
174  
-            // Calculate f'(x[i]), where: x[i] = $xR.
175  
-            $d1xR = Math_Numerical_RootFinding_Common::getEqResult($dfx1Function, $xR);
176  
-
177  
-            // Calculate f''(x[i]), where: x[i] = $xR.
178  
-            $d2xR = Math_Numerical_RootFinding_Common::getEqResult($dfx2Function, $xR);
179  
-
180  
-            // Avoid division by zero.
181  
-            if (pow($d1xR, 2) - ($fxR * $d2xR) == 0) {
182  
-                return PEAR::raiseError('Iteration skipped, division by zero');
183  
-            }
184  
-
185  
-            // Newton-Raphson's formula.
186  
-            $xN = $xR - (($fxR * $d1xR) / (pow($d1xR, 2) - ($fxR * $d2xR)));
187  
-
188  
-            // xR is the root.
189  
-            if ($xN == 0) {
190  
-                $this->root = $xR;
191  
-                break;
192  
-            }
193  
-
194  
-            // Compute error.
195  
-            $this->epsError = abs(($xN - $xR) / $xN);
196  
-            $epsErrors[] = $this->epsError;
197  
-
198  
-            // Detect for divergent rows.
199  
-            if ($this->isDivergentRows($epsErrors) &&
200  
-                $this->options['divergent_skip'])
201  
-            {
202  
-                return PEAR::raiseError('Iteration skipped, divergent rows detected');
203  
-                break;
204  
-            }
205  
-
206  
-            // Check for error tolerance, if lower than or equal with
207  
-            // $errTolerance it is the root.
208  
-            if ($this->epsError <= $errTolerance) {
209  
-                $this->root = $xR;
210  
-                break;
211  
-            }
212  
-
213  
-            // Switch x[i+1] -> x[i], where: x[i] = $xR and x[i+1] = $xN.
214  
-            $xR = $xN;
215  
-        }
216  
-        $this->iterationCount = $i;
217  
-        return $this->root;
218  
-    }
219  
-
220  
-    // }}}
221  
-}
222  
-
223  
-/*
224  
- * Local variables:
225  
- * mode: php
226  
- * tab-width: 4
227  
- * c-basic-offset: 4
228  
- * c-hanging-comment-ender-p: nil
229  
- * End:
230  
- */
231  
-?>
231  Math/Numerical/RootFinding/Ralstonrabinowitz.php
... ...
@@ -1,231 +0,0 @@
1  
-<?php
2  
-/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3  
-// {{{ Header
4  
-// +----------------------------------------------------------------------+
5  
-// | PEAR, the PHP Extension and Application Repository                   |
6  
-// +----------------------------------------------------------------------+
7  
-// | PHP version 4                                                        |
8  
-// +----------------------------------------------------------------------+
9  
-// | Copyright (C) 2004  Firman Wandayandi                                |
10  
-// | All rights reserved.                                                 |
11  
-// +----------------------------------------------------------------------+
12  
-// | Redistribution and use in source and binary forms, with or without   |
13  
-// | modification, are permitted provided that the following conditions   |
14  
-// | are met:                                                             |
15  
-// |                                                                      |
16  
-// |   Redistributions of source code must retain the above copyright     |
17  
-// |   notice, this list of conditions and the following disclaimer.      |
18  
-// |                                                                      |
19  
-// |   Redistributions in binary form must reproduce the above            |
20  
-// |   copyright notice, this list of conditions and the following        |
21  
-// |   disclaimer in the documentation and/or other materials provided    |
22  
-// |   with the distribution.                                             |
23  
-// |                                                                      |
24  
-// |   Neither the name of Firman Wandayandi nor the names of             |
25  
-// |   contributors may be used to endorse or promote products derived    |
26  
-// |   from this software without specific prior written permission.      |
27  
-// |                                                                      |
28  
-// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29  
-// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30  
-// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31  
-// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE       |
32  
-// | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,  |
33  
-// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34  
-// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;     |
35  
-// | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER     |
36  
-// | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT   |
37  
-// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN    |
38  
-// | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE      |
39  
-// | POSSIBILITY OF SUCH DAMAGE.                                          |
40  
-// +----------------------------------------------------------------------+
41  
-// | Authors: Firman Wandayandi <firman@php.net>                          |
42  
-// +----------------------------------------------------------------------+
43  
-// }}}
44  
-// $Id$
45  
-
46  
-/**
47  
- * Driver file contains Math_Numerical_RootFinding_Bisection class to provide
48  
- * Ralston and Rabinowitz method root finding calculation.
49  
- *
50  
- * @author Firman Wandayandi <firman@php.net>
51  
- * @package Math_Numerical_RootFinding
52  
- * @subpackage Methods
53  
- * @category Math
54  
- * @license http://www.opensource.org/licenses/bsd-license.php
55  
- *          BSD License
56  
- */
57  
-
58  
-// {{{ Dependencies
59  
-
60  
-/**
61  
- * Load Math_Numerical_RootFinding_Common as base class.
62  
- */
63  
-require_once 'Math/Numerical/RootFinding/Common.php';
64  
-
65  
-// }}}
66  
-
67  
-/**
68  
- * Ralston and Rabinowitz method class.
69  
- *
70  
- * @author Firman Wandayandi <firman@php.net>
71  
- * @package Math_Numerical_RootFinding
72  
- * @subpackage Methods
73  
- */
74  
-class Math_Numerical_RootFinding_Ralstonrabinowitz
75  
-extends Math_Numerical_RootFinding_Common
76  
-{
77  
-    // {{{ Constructor
78  
-
79  
-    /**
80  
-     * PHP4 compatible constructor.
81  
-     *
82  
-     * @param array $options Options.
83  
-     *
84  
-     * @access public
85  
-     */
86  
-    function Math_Numerical_RootFinding_Ralstonrabinowitz($options = null)
87  
-    {
88  
-        parent::__construct($options);
89  
-    }
90  
-
91  
-    // }}}
92  
-    // {{{ infoCompute()
93  
-
94  
-    /**
95  
-     * Print out parameters description for compute() function.
96  
-     *
97  
-     * @access public
98  
-     */
99  
-    function infoCompute()
100  
-    {
101  
-        print "<h2>False Position::compute()</h2>\n" .
102  
-
103  
-              "<em>float</em> | <em>PEAR_Error</em> " .
104  
-              "<strong>compute</strong>(<u>\$fxFunction</u>, " .
105  
-              "<u>\$dfxFunction</u>, <u>\$xR0</u>, " .
106  
-              "<u>\$xR1</u>)<br />\n" .
107  
-
108  
-              "<h3>Description</h3>\n" .
109  
-              "<em>callback</em> <u>\$fxFunction</u> Callback f(x) equation " .
110  
-              "function or object/method tuple.<br>\n" .
111  
-
112  
-              "<em>callback</em> <u>\$dfxFunction</u> Callback f'(x) " .
113  
-              "equation function or object/method tuple.<br>\n" .
114  
-
115  
-              "<em>float</em> <u>\$xR0</u> First initial guess.<br>\n" .
116  
-
117  
-              "<em>float</em> <u>\$xR1</u> Second initial guess.<br>\n";
118  
-    }
119  
-
120  
-    // }}}
121  
-    // {{{ compute()
122  
-
123  
-    /**
124  
-     * Ralston and Rabinowitz method for calculate double root (twin root).
125  
-     *
126  
-     * @param callback $fxFunction Callback f(x) equation function or
127  
-     *                             object/method tuple.
128  
-     * @param callback $dxFunction Callback f'(x) equation function or
129  
-     *                             object/method tuple.
130  
-     * @param float $xR0 First initial guess.
131  
-     * @param float $xR1 Second initial guess.
132  
-     *
133  
-     * @return float|PEAR_Error Root value on success or PEAR_Error on failure.
134  
-     * @access public
135  
-     * @see Math_Numerical_RootFinding_Common::validateEqFunction()
136  
-     * @see Math_Numerical_RootFinding_Common::getEqResult()
137  
-     * @see Math_Numerical_RootFinding_Common::isDivergentRow()
138  
-     * @see Math_Numerical_RootFinding_Secant::compute()
139  
-     */
140  
-    function compute($fxFunction, $dxFunction, $xR0, $xR1)
141  
-    {
142  
-        // Validate f(x) equation function.
143  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($fxFunction);
144  
-        if (PEAR::isError($err)) {
145  
-            return $err;
146  
-        }
147  
-
148  
-        // Validate f'(x) equation function.
149  
-        $err = Math_Numerical_RootFinding_Common::validateEqFunction($dxFunction);
150  
-        if (PEAR::isError($err)) {
151  
-            return $err;
152  
-        }
153  
-
154  
-        // Sets maximum iteration and tolerance from options.
155  
-        $maxIteration = $this->options['max_iteration'];
156  
-        $errTolerance = $this->options['err_tolerance'];
157  
-
158  
-        // Sets variable for saving errors during iteration, for divergent
159  
-        // detection.
160  
-        $epsErrors = array();
161  
-
162  
-        for($i = 1; $i <= $maxIteration; $i++) {
163  
-            // Calculate f(x[i-1]) and f'(x[1]), where: x[i-1] = $xR0.
164  
-            $fxR0 = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xR0);
165  
-            $dxR0 = Math_Numerical_RootFinding_Common::getEqResult($dxFunction, $xR0);
166  
-
167  
-            // Calculate f(x[i]) and f'(x[1]), where: x[i] = $xR1.
168  
-            $fxR1 = Math_Numerical_RootFinding_Common::getEqResult($fxFunction, $xR1);
169  
-            $dxR1 = Math_Numerical_RootFinding_Common::getEqResult($dxFunction, $xR1);
170  
-
171  
-            // Calculate f(x[i-1]) / f'(x[i-1], where x[i-1] = $xR0.
172  
-            $uxR0 = $fxR0 / $dxR0;
173  
-
174  
-            // Calculate f(x[i]) / f'(x[i]), where x[i] = $xR1;
175  
-            $uxR1 = $fxR1 / $dxR1;
176  
-
177  
-            // Avoid division by zero.
178  
-            if ($uxR0 - $uxR1 == 0) {
179  
-                return PEAR::raiseError('Iteration skipped division by zero');
180  
-            }
181  
-
182  
-            // Ralston and Rabinowitz's formula.
183  
-            $xN = $xR1 - ($uxR1 * ($xR0 - $xR1) / ($uxR0 - $uxR1));
184  
-
185  
-            // xR is the root.
186  
-            if ($xN == 0) {
187  
-                $this->root = $xR;
188  
-                break;
189  
-            }
190  
-
191  
-            // Compute error.
192  
-            $this->epsError = abs(($xN - $xR1) / $xN);
193  
-            $epsErrors[] = $this->epsError;
194  
-
195  
-            // Detect for divergent rows.
196  
-            if ($this->isDivergentRows($epsErrors) &&
197  
-                $this->options['divergent_skip'])
198  
-            {
199  
-                return PEAR::raiseError('Iteration skipped, divergent rows detected');
200  
-                break;
201  
-            }
202  
-
203  
-            // Check for error tolerance, if lower than or equal with
204  
-            // $errTolerance it is the root.