Class Differentiation

java.lang.Object
cloud.opencode.base.math.analysis.Differentiation

public final class Differentiation extends Object
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 Details

    • derivative

      public static double derivative(DoubleUnaryOperator f, double x)
      Computes the first derivative of f at x using 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

      public static double derivative(DoubleUnaryOperator f, double x, double h)
      Computes the first derivative of f at x using 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

      public static double secondDerivative(DoubleUnaryOperator f, double x)
      Computes the second derivative of f at x using 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

      public static double secondDerivative(DoubleUnaryOperator f, double x, double h)
      Computes the second derivative of f at x using 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

      public static double richardson(DoubleUnaryOperator f, double x, int order)
      Computes the first derivative of f at x using 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