public class ZeroSystem extends Object implements Serializable, Cloneable
ZeroSystem
is based on the MINPACK subroutine HYBRDJ
, which uses a modification of M.J.D. Powell's hybrid algorithm. This
algorithm is a variation of Newton's method, which uses a finite-difference
approximation to the Jacobian and takes precautions to avoid large step sizes
or increasing residuals. For further description, see More et al. (1980).
A finite-difference method is used to estimate the Jacobian. Whenever the
exact Jacobian can be easily provided, objectF
should implement
ZeroSystem.Jacobian
.
Note that one can use the JDK 1.4 JAVA Logging API to generate intermediate output for the solver. Accumulated levels of detail correspond to JAVA's CONFIG, FINE, FINER, and FINEST logging levels with CONFIG yielding the smallest amount of information and FINEST yielding the most. The levels of output yield the following:
Level | Output |
CONFIG | Iteration increments are printed. |
FINE | Prints convergnce tests. |
FINER | Intermediate solution values are provided. |
FINEST | Tracks progress through internal methods. |
Modifier and Type | Class and Description |
---|---|
static class |
ZeroSystem.DidNotConvergeException
The iteration did not converge.
|
static interface |
ZeroSystem.Function
Public interface for user supplied function to
ZeroSystem
object. |
static interface |
ZeroSystem.Jacobian
Public interface for user supplied function to
ZeroSystem
object. |
static class |
ZeroSystem.ToleranceTooSmallException
Tolerance too small
|
static class |
ZeroSystem.TooManyIterationsException
Too many iterations.
|
Constructor and Description |
---|
ZeroSystem(int n)
Creates an object to find the zeros of a system of n equations.
|
Modifier and Type | Method and Description |
---|---|
Logger |
getLogger()
Returns the logger object.
|
void |
setGuess(double[] xguess)
Sets the initial estimate of the root.
|
void |
setMaxIterations(int maxIterations)
Sets the maximum number of iterations allowed.
|
void |
setRelativeError(double errorRelative)
Sets the relative error tolerance.
|
double[] |
solve(ZeroSystem.Function objectF)
Solve a system of nonlinear equations using the modified Powell hybrid
algorithm
|
public ZeroSystem(int n)
n
- an int
indicating the number of equations to be
solved and the number of unknowns.public void setGuess(double[] xguess)
xguess
to all zeros.xguess
- a double
array containing the initial guess.
The length of xguess
must be equal to the
number of equations.public void setMaxIterations(int maxIterations)
maxIterations
- an int
specifying the maximum
number of iterations allowedIllegalArgumentException
- is thrown if maxIterations
is less than or equal to zero.public void setRelativeError(double errorRelative)
errorRelative
- a double
specifying the relative
error toleranceIllegalArgumentException
- is thrown if errorRelative
is less than 0 or
greater than 1.public Logger getLogger()
java.util.logging.Logger
object, if present, or
null
.public double[] solve(ZeroSystem.Function objectF) throws ZeroSystem.TooManyIterationsException, ZeroSystem.ToleranceTooSmallException, ZeroSystem.DidNotConvergeException
objectF
- a ZeroSystem.Function
that defines the
function whose zero is to be found. If objectF
implements a Jacobian then its Jacobian is used. Otherwise
a finite difference is computed.double
array containing the solutionZeroSystem.TooManyIterationsException
- is thrown if the
maximum number of iterations is exceededZeroSystem.ToleranceTooSmallException
- is thrown if the error tolerance
is too smallZeroSystem.DidNotConvergeException
- is thrown if the algorithm does
not convergeZeroSystem.Jacobian
Copyright © 2020 Rogue Wave Software. All rights reserved.