XLPack 6.1
Python API Reference Manual
Loading...
Searching...
No Matches

◆ dfzero()

def dfzero ( ,
,
,
,
re  = 1.0e-10,
ae  = 1.0e-10 
)

Solution of a single general nonlinear equation

Purpose
dfzero searches for a zero of a function f(x) between the given values b and c until the width of the interval [b, c] has collapsed to within a tolerance specified by the stopping criterion, abs(b - c) <= 2*(re*abs(b) + ae).
It is designed primarily for problems where f(b) and f(c) have opposite signs. The method used is an efficient combination of bisection and the secant rule.
Returns
(x, info)

x (float):
The final approximation to a zero.

info (int):
= 0: Normal return
= -1: The argument f is invalid
= 1: f(x) = 0, however the interval may not have collapsed to the requested tolerance
= 2: b may be near a singular point of f(x)
= 3: No change in sign of f(x) was found although the interval
= 4: Too many (> 500) function evaluations used
Parameters
[in]fUser supplied function which evaluates f(x) for the equation f(x) = 0 defined as follows: _CODE def f(x): return computed function value f(x) _ENDCODE
[in]bLower endpoint of the initial interval.
[in]cUpper endpoint of the initial interval.
[in]rA (better) guess of a zero of f which could help in speeding up convergence. When no better guess is known, it is recommended that r be set to b or c.
[in]re(Optional)
Relative error used for the stopping criterion. If the requested re is less than machine precision, then it is set to approximately machine precision. (default = 1.0e-10)
[in]ae(Optional)
Absolute error used in the stopping criterion. If the given interval [b, c] contains the origin, then a nonzero value should be chosen for ae. (default = 1.0e-10)
Reference
D. Kahaner, C. Moler, S. Nash, "Numerical Methods and Software", Prentice-Hall (1989)
Example Program
Find the root of the following equation in the interval [1, 3].
x^3 - 2x - 5 = 0
def f(x):
return (x*x - 2.0)*x - 5.0
def TestDfzero():
b = 1.0
c = 3.0
r = b
print(b, c)
x, info = dfzero(f, b, c, r)
print(x, info)
def dfzero(f, b, c, r, re=1.0e-10, ae=1.0e-10)
Solution of a single general nonlinear equation
Example Results
>>> TestDfzero()
1.0 3.0
2.0945514814433284 0