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('

モジュール mbcp.mp_math.function

AAA

func 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('',1),o=[d],k=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("mi",null,"f"),s("mo",{stretchy:"false"},"("),s("mi",null,"x"),s("mo",null,","),s("mi",null,"y"),s("mo",null,","),s("mi",null,"z"),s("mo",{stretchy:"false"},")")])],-1),m={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},g={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-0.566ex"},xmlns:"http://www.w3.org/2000/svg",width:"10.19ex",height:"2.262ex",role:"img",focusable:"false",viewBox:"0 -750 4504 1000","aria-hidden":"true"},c=a('',1),u=[c],y=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("mo",{stretchy:"false"},"("),s("msub",null,[s("mi",null,"x"),s("mn",null,"0")]),s("mo",null,","),s("msub",null,[s("mi",null,"y"),s("mn",null,"0")]),s("mo",null,","),s("msub",null,[s("mi",null,"z"),s("mn",null,"0")]),s("mo",{stretchy:"false"},")")])],-1),E={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},F={style:{overflow:"visible","min-height":"1px","min-width":"1px","vertical-align":"-1.469ex"},xmlns:"http://www.w3.org/2000/svg",width:"29.427ex",height:"4.07ex",role:"img",focusable:"false",viewBox:"0 -1149.5 13006.8 1799","aria-hidden":"true"},f=a('',1),_=[f],C=s("mjx-assistive-mml",{unselectable:"on",display:"inline",style:{top:"0px",left:"0px",clip:"rect(1px, 1px, 1px, 1px)","-webkit-touch-callout":"none","-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none",position:"absolute",padding:"1px 0px 0px 0px",border:"0px",display:"block",width:"auto",overflow:"hidden"}},[s("math",{xmlns:"http://www.w3.org/1998/Math/MathML"},[s("mi",{mathvariant:"normal"},"∇"),s("mi",null,"f"),s("mo",{stretchy:"false"},"("),s("msub",null,[s("mi",null,"x"),s("mn",null,"0")]),s("mo",null,","),s("msub",null,[s("mi",null,"y"),s("mn",null,"0")]),s("mo",null,","),s("msub",null,[s("mi",null,"z"),s("mn",null,"0")]),s("mo",{stretchy:"false"},")"),s("mo",null,"="),s("mrow",{"data-mjx-texclass":"INNER"},[s("mo",{"data-mjx-texclass":"OPEN"},"("),s("mfrac",null,[s("mrow",null,[s("mi",null,"∂"),s("mi",null,"f")]),s("mrow",null,[s("mi",null,"∂"),s("mi",null,"x")])]),s("mo",null,","),s("mfrac",null,[s("mrow",null,[s("mi",null,"∂"),s("mi",null,"f")]),s("mrow",null,[s("mi",null,"∂"),s("mi",null,"y")])]),s("mo",null,","),s("mfrac",null,[s("mrow",null,[s("mi",null,"∂"),s("mi",null,"f")]),s("mrow",null,[s("mi",null,"∂"),s("mi",null,"z")])]),s("mo",{"data-mjx-texclass":"CLOSE"},")")])])],-1),w=a(`

引数:

戻り値: 梯度

ソースコード または GitHubで表示
python
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)

func curry(func: MultiVarsFunc, *args: Var) -> OneVarFunc

説明: 对多参数函数进行柯里化。

TIP

有关函数柯里化,可参考函数式编程--柯理化(Currying)

引数:

戻り値: 柯里化后的函数

:

python
def add(a: int, b: int, c: int) -> int:
    return a + b + c
add_curried = curry(add, 1, 2)
add_curried(3)  # 6
ソースコード または GitHubで表示
python
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
`,13);function x(b,L,H,M,B,v){return i(),t("div",null,[Q,s("div",T,[h,s("p",null,[n("已知一个函数"),s("mjx-container",p,[(i(),t("svg",r,o)),k]),n(",则其在点"),s("mjx-container",m,[(i(),t("svg",g,u)),y]),n("处的梯度向量为: "),s("mjx-container",E,[(i(),t("svg",F,_)),C])])]),w])}const V=l(e,[["render",x]]);export{Z as __pageData,V as default};