import{_ as l,c as t,j as s,a as n,a4 as a,o as i}from"./chunks/framework.DpC1ZpOZ.js";const Z=JSON.parse('{"title":"mbcp.mp_math.function","description":"","frontmatter":{"title":"mbcp.mp_math.function","lastUpdated":false},"headers":[],"relativePath":"ja/api/mp_math/function.md","filePath":"ja/api/mp_math/function.md"}'),e={name:"ja/api/mp_math/function.md"},Q=a('
説明: AAA
cal_gradient_3vf(func: ThreeSingleVarsFunc, p: Point3, epsilon: float = EPSILON) -> Vector3
説明: 计算三元函数在某点的梯度向量。
',4),T={class:"tip custom-block github-alert"},h=s("p",{class:"custom-block-title"},"TIP",-1),p={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},r={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"8.471ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 3744.3 1000","aria-hidden":"true"},d=a('引数:
- func (
ThreeSingleVarsFunc
): 三元函数- p (
Point3
): 点- epsilon: 偏移量
戻り値: 梯度
def cal_gradient_3vf(func: ThreeSingleVarsFunc, p: Point3, epsilon: float=EPSILON) -> Vector3:
"""
计算三元函数在某点的梯度向量。
> [!tip]
> 已知一个函数$f(x, y, z)$,则其在点$(x_0, y_0, z_0)$处的梯度向量为:
$\\\\nabla f(x_0, y_0, z_0) = \\\\left(\\\\frac{\\\\partial f}{\\\\partial x}, \\\\frac{\\\\partial f}{\\\\partial y}, \\\\frac{\\\\partial f}{\\\\partial z}\\\\right)$
Args:
func ([\`ThreeSingleVarsFunc\`](./mp_math_typing#var-threesinglevarsfunc)): 三元函数
p ([\`Point3\`](./point#class-point3)): 点
epsilon: 偏移量
Returns:
梯度
"""
dx = (func(p.x + epsilon, p.y, p.z) - func(p.x - epsilon, p.y, p.z)) / (2 * epsilon)
dy = (func(p.x, p.y + epsilon, p.z) - func(p.x, p.y - epsilon, p.z)) / (2 * epsilon)
dz = (func(p.x, p.y, p.z + epsilon) - func(p.x, p.y, p.z - epsilon)) / (2 * epsilon)
return Vector3(dx, dy, dz)
curry(func: MultiVarsFunc, *args: Var) -> OneVarFunc
説明: 对多参数函数进行柯里化。
TIP
有关函数柯里化,可参考函数式编程--柯理化(Currying)
引数:
- func (
MultiVarsFunc
): 函数- *args (
Var
): 参数
戻り値: 柯里化后的函数
例:
def add(a: int, b: int, c: int) -> int:
return a + b + c
add_curried = curry(add, 1, 2)
add_curried(3) # 6
def curry(func: MultiVarsFunc, *args: Var) -> OneVarFunc:
"""
对多参数函数进行柯里化。
> [!tip]
> 有关函数柯里化,可参考[函数式编程--柯理化(Currying)](https://zhuanlan.zhihu.com/p/355859667)
Args:
func ([\`MultiVarsFunc\`](./mp_math_typing#var-multivarsfunc)): 函数
*args ([\`Var\`](./mp_math_typing#var-var)): 参数
Returns:
柯里化后的函数
Examples:
\`\`\`python
def add(a: int, b: int, c: int) -> int:
return a + b + c
add_curried = curry(add, 1, 2)
add_curried(3) # 6
\`\`\`
"""
def curried_func(*args2: Var) -> Var:
"""@litedoc-hide"""
return func(*args, *args2)
return curried_func