求导数 Function derivative #
对以解析器节点表示的表达式求导数。导数将针对第二个参数中提供的变量进行计算。如果表达式中存在多个变量,则返回偏导数。
这使用了微分规则,可以在此处找到:
Syntax #
math.derivative(expr, variable)
math.derivative(expr, variable, options)
Parameters #
| Parameter | Type | Description |
|---|---|---|
expr |
Node | string | 要微分的表达式 The expression to differentiate |
变量 variable |
SymbolNode | string | 用于求导的变量 The variable over which to differentiate |
options |
{simplify: boolean} | 有一个可用选项 simplify,默认为 true。当设置为 false 时,输出将不会被简化。 |
Returns #
| Type | Description |
|---|---|
| ConstantNode | SymbolNode | ParenthesisNode | FunctionNode | OperatorNode | expr 的导数 The derivative of expr |
Throws #
Type | Description —- | ———–
Examples #
math.derivative('x^2', 'x') // Node '2 * x'
math.derivative('x^2', 'x', {simplify: false}) // Node '2 * 1 * x ^ (2 - 1)'
math.derivative('sin(2x)', 'x')) // Node '2 * cos(2 * x)'
math.derivative('2*x', 'x').evaluate() // number 2
math.derivative('x^2', 'x').evaluate({x: 4}) // number 8
const f = math.parse('x^2')
const x = math.parse('x')
math.derivative(f, x) // Node {2 * x}