java fast math,Java FastMath.ulp方法代码示例

import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类

/**

* Build a differentiator with number of points and step size when independent variable is bounded.

*

* When the independent variable is bounded (tLower < t < tUpper), the sampling

* points used for differentiation will be adapted to ensure the constraint holds

* even near the boundaries. This means the sample will not be centered anymore in

* these cases. At an extreme case, computing derivatives exactly at the lower bound

* will lead the sample to be entirely on the right side of the derivation point.

*

*

* Note that the boundaries are considered to be excluded for function evaluation.

*

*

* Beware that wrong settings for the finite differences differentiator

* can lead to highly unstable and inaccurate results, especially for

* high derivation orders. Using very small step sizes is often a

* bad idea.

*

* @param nbPoints number of points to use

* @param stepSize step size (gap between each point)

* @param tLower lower bound for independent variable (may be {@code Double.NEGATIVE_INFINITY}

* if there are no lower bounds)

* @param tUpper upper bound for independent variable (may be {@code Double.POSITIVE_INFINITY}

* if there are no upper bounds)

* @exception NotPositiveException if {@code stepsize <= 0} (note that

* {@link NotPositiveException} extends {@link NumberIsTooSmallException})

* @exception NumberIsTooSmallException {@code nbPoint <= 1}

* @exception NumberIsTooLargeException {@code stepSize * (nbPoints - 1) >= tUpper - tLower}

*/

public FiniteDifferencesDifferentiator(final int nbPoints, final double stepSize,

final double tLower, final double tUpper)

throws NotPositiveException, NumberIsTooSmallException, NumberIsTooLargeException {

if (nbPoints <= 1) {

throw new NumberIsTooSmallException(stepSize, 1, false);

}

this.nbPoints = nbPoints;

if (stepSize <= 0) {

throw new NotPositiveException(stepSize);

}

this.stepSize = stepSize;

halfSampleSpan = 0.5 * stepSize * (nbPoints - 1);

if (2 * halfSampleSpan >= tUpper - tLower) {

throw new NumberIsTooLargeException(2 * halfSampleSpan, tUpper - tLower, false);

}

final double safety = FastMath.ulp(halfSampleSpan);

this.tMin = tLower + halfSampleSpan + safety;

this.tMax = tUpper - halfSampleSpan - safety;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值