Class Differentiation
java.lang.Object
cloud.opencode.base.math.analysis.Differentiation
Numerical differentiation utilities using finite difference methods.
使用有限差分法的数值微分工具
Provides central difference approximations for first and second derivatives, as well as Richardson extrapolation for improved accuracy. All methods are stateless and thread-safe.
提供一阶和二阶导数的中心差分近似, 以及理查森外推法以提高精度。所有方法无状态且线程安全。
- Since:
- JDK 25, opencode-base-math V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublederivative(DoubleUnaryOperator f, double x) Computes the first derivative offatxusing central difference.static doublederivative(DoubleUnaryOperator f, double x, double h) Computes the first derivative offatxusing central difference with an explicit step size.static doublerichardson(DoubleUnaryOperator f, double x, int order) Computes the first derivative offatxusing Richardson extrapolation.static doublesecondDerivative(DoubleUnaryOperator f, double x) Computes the second derivative offatxusing central difference.static doublesecondDerivative(DoubleUnaryOperator f, double x, double h) Computes the second derivative offatxusing central difference with an explicit step size.
-
Method Details
-
derivative
Computes the first derivative offatxusing central difference. 使用中心差分法计算函数 f 在 x 处的一阶导数The step size is automatically chosen as
max(1e-8, |x| * 1e-8).步长自动选择为
max(1e-8, |x| * 1e-8)。- Parameters:
f- the function / 函数x- the point at which to differentiate / 求导点- Returns:
- the approximate first derivative / 近似一阶导数
- Throws:
MathException- if inputs are invalid
-
derivative
Computes the first derivative offatxusing central difference with an explicit step size. 使用指定步长的中心差分法计算函数 f 在 x 处的一阶导数- Parameters:
f- the function / 函数x- the point at which to differentiate / 求导点h- the step size (must be positive) / 步长(必须为正)- Returns:
- the approximate first derivative / 近似一阶导数
- Throws:
MathException- if inputs are invalid
-
secondDerivative
Computes the second derivative offatxusing central difference. 使用中心差分法计算函数 f 在 x 处的二阶导数The step size is automatically chosen as
max(1e-5, |x| * 1e-5).步长自动选择为
max(1e-5, |x| * 1e-5)。- Parameters:
f- the function / 函数x- the point at which to differentiate / 求导点- Returns:
- the approximate second derivative / 近似二阶导数
- Throws:
MathException- if inputs are invalid
-
secondDerivative
Computes the second derivative offatxusing central difference with an explicit step size. 使用指定步长的中心差分法计算函数 f 在 x 处的二阶导数- Parameters:
f- the function / 函数x- the point at which to differentiate / 求导点h- the step size (must be positive) / 步长(必须为正)- Returns:
- the approximate second derivative / 近似二阶导数
- Throws:
MathException- if inputs are invalid
-
richardson
Computes the first derivative offatxusing Richardson extrapolation. 使用理查森外推法计算函数 f 在 x 处的一阶导数Richardson extrapolation improves accuracy by combining central difference estimates at decreasing step sizes using a Neville-like extrapolation tableau. Higher orders yield more accurate results for smooth functions.
理查森外推法通过在递减步长下组合中心差分估计, 使用类似 Neville 的外推表来提高精度。对于光滑函数,更高阶数可获得更精确的结果。
- Parameters:
f- the function / 函数x- the point at which to differentiate / 求导点order- the extrapolation order, in [1, 6] / 外推阶数,范围 [1, 6]- Returns:
- the most accurate derivative estimate / 最精确的导数估计
- Throws:
MathException- if inputs are invalid
-