public class NumericalDerivativesEx4 extends NumericalDerivatives
Approximates the gradient using central divided differences.
This example uses the same data as in exampleNumericalDerivativesEx3
.
Instead of the one-sided difference, the central difference method is used.
Agreement should be approximately the two-thirds power of machine precision.
That agreement is achieved here. Generally this is the most accuracy
one can expect using central divided differences. Note that using central
differences requires essentially twice the number of evaluations of the
function compared with obtaining one-sided differences. This can be a
significant issue for functions that are expensive to evaluate. This example
shows how to override evaluateF
.NumericalDerivatives.Function, NumericalDerivatives.Jacobian
ACCUMULATE, CENTRAL, ONE_SIDED, SKIP
Constructor and Description |
---|
NumericalDerivativesEx4(NumericalDerivatives.Function fcn) |
Modifier and Type | Method and Description |
---|---|
double[] |
evaluateF(int varIndex,
double[] y)
This method is provided by the user to compute the function values at
the current independent variable values
y . |
static void |
main(String[] args) |
evaluateJ, getPercentageFactor, getScalingFactors, getStatus, setDifferencingMethods, setInitialF, setPercentageFactor, setScalingFactors
public NumericalDerivativesEx4(NumericalDerivatives.Function fcn)
public double[] evaluateF(int varIndex, double[] y)
NumericalDerivatives
y
. If the user
does not override the evaluateF
method, then
NumericalDerivatives.Function.f
is used to compute the
function values.evaluateF
in class NumericalDerivatives
varIndex
- an int
which indicates the index of the
variable to perturb.y
- a double
array of length n, the point
at which the function is to be evaluated.double
array of length m. The
equations evaluated at the point y
.public static void main(String[] args)
Copyright © 2020 Rogue Wave Software. All rights reserved.