跳转到内容

平滑数学函数

本节中的函数是原始数学函数的平滑等效版本,可用于在间断点附近计算导数。

smooth_abs

T smooth_abs(T x, T c = 0.001)abs 的平滑版本,其定义为:

\[ \text{smooth\_abs}(x,c) = \left\{\begin{array}{lll} |x| & & \text{如果 }x < c\text{ 或 } x > c\\[5pt] x^2\left(\frac{2}{c}-\frac{1}{c^2} x\right) & & \text{如果 }0 \leq x \leq c\\[5pt] x^2\left(\frac{2}{c}+\frac{1}{c^2} x\right) & & \text{如果 }-c \leq x < 0 \end{array}\right. \]
  • x是输入值
  • c 是样条近似区域的截止点(默认值:0.001
  • returns: 平滑后的绝对值,定义如上所述。

smooth_max

T smooth_max(T x, T y, T c = 0.001)max 函数的平滑版本,其定义为:

\[ \text{smooth\_max}(x,y,c) = 0.5\left(x+y+\text{smooth\_abs}(x-y,c)\right) \]
  • x max函数的第一个参数
  • y max函数的第二个参数
  • c 样条近似区域的截止点(默认值:0.001
  • returns: 平滑最大值函数,定义如上

smooth_min

T smooth_min(T x, T y, T c = 0.001)min 函数的平滑版本,其定义为:

\[ \text{smooth\_min}(x,y,c) = 0.5\left(x+y-\text{smooth\_abs}(x-y,c)\right) \]
  • x min函数的第一个参数
  • y min函数的第二个参数
  • c 样条近似区域的截断点(默认值:0.001
  • returns: 平滑最小值函数,定义如上所述