import{_ as i,c as s,j as t,a as T,a2 as a,o as Q}from"./chunks/framework.C94oF1kp.js";const v=JSON.parse('{"title":"mbcp.mp_math.function","description":"","frontmatter":{"title":"mbcp.mp_math.function","editLink":false},"headers":[],"relativePath":"zht/api/mp_math/function.md","filePath":"zht/api/mp_math/function.md"}'),l={name:"zht/api/mp_math/function.md"},n=a('
説明: AAA
cal_gradient_3vf(func: ThreeSingleVarsFunc, p: Point3, epsilon: float = EPSILON) -> Vector3
説明: 计算三元函数在某点的梯度向量。
',4),e={class:"tip custom-block github-alert"},h=t("p",{class:"custom-block-title"},"TIP",-1),r={class:"MathJax",jax:"SVG",style:{direction:"ltr",position:"relative"}},d={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"},p=a('變數説明:
- func: 三元函数
- p: 点
- 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: 三元函数
p: 点
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)