类 NewtonRaphson
java.lang.Object
cn.nkpro.elcube.utils.xirr.NewtonRaphson
Simple implementation of the Newton-Raphson method for finding roots or
inverses of a function.
The function and its derivative must be supplied as instances of DoubleUnaryOperator and the answers are computed as doubles.
For examples of usage, see the source of the test class or the Xirr class.
The iterations parameter is used as an upper bound on the number
of iterations to run the method for.
The tolerance parameter is used to determine when the method
has been successful. If the value of the function at the candidate input
is within the tolerance of the desired target value, the
method terminates.
-
嵌套类概要
嵌套类 -
字段概要
字段 -
构造器概要
构造器构造器说明NewtonRaphson(DoubleUnaryOperator func, DoubleUnaryOperator derivative, double tolerance, long iterations)Construct an instance of the NewtonRaphson method for masochists who do not want to usebuilder(). -
方法概要
修饰符和类型方法说明static NewtonRaphson.Builderbuilder()Convenience method for getting an instance of aNewtonRaphson.Builder.doublefindRoot(double guess)Equivalent toinverse(0, guess).doubleinverse(double target, double guess)Find the input value to the function which yields the giventarget, starting at theguess.
-
字段详细资料
-
TOLERANCE
public static final double TOLERANCEDefault tolerance.- 另请参阅:
- 常量字段值
-
-
构造器详细资料
-
NewtonRaphson
public NewtonRaphson(DoubleUnaryOperator func, DoubleUnaryOperator derivative, double tolerance, long iterations)Construct an instance of the NewtonRaphson method for masochists who do not want to usebuilder().- 参数:
func- the functionderivative- the derivative of the functiontolerance- the toleranceiterations- maximum number of iterations
-
-
方法详细资料
-
builder
Convenience method for getting an instance of aNewtonRaphson.Builder.- 返回:
- new Builder
-
findRoot
public double findRoot(double guess)Equivalent toinverse(0, guess).Find a root of the function starting at the given guess. Equivalent to invoking
inverse(0, guess). Finds the input value x such that |f(x)| < tolerance.- 参数:
guess- the value to start at- 返回:
- an input to the function which yields zero within the given tolerance
- 另请参阅:
inverse(double, double)
-
inverse
public double inverse(double target, double guess)Find the input value to the function which yields the giventarget, starting at theguess. More precisely, finds an input value x such that |f(x) -target| < tolerance- 参数:
target- the target value of the functionguess- value to start the algorithm with- 返回:
- the inverse of the function at
targetwithin the given tolerance - 抛出:
ZeroValuedDerivativeException- if the derivative is 0 while executing the Newton-Raphson methodOverflowException- when a value involved is infinite or NaNNonconvergenceException- if the method fails to converge in the given number of iterations
-