UNPKG

1.72 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function derivative
4
5Takes the derivative of an expression expressed in parser Nodes.
6The derivative will be taken over the supplied variable in the
7second parameter. If there are multiple variables in the expression,
8it will return a partial derivative.
9
10This uses rules of differentiation which can be found here:
11
12- [Differentiation rules (Wikipedia)](https://en.wikipedia.org/wiki/Differentiation_rules)
13
14
15## Syntax
16
17```js
18derivative(expr, variable)
19derivative(expr, variable, options)
20```
21
22### Parameters
23
24Parameter | Type | Description
25--------- | ---- | -----------
26`expr` | Node &#124; string | The expression to differentiate
27`variable` | SymbolNode &#124; string | The variable over which to differentiate
28`options` | {simplify: boolean} | There is one option available, `simplify`, which is true by default. When false, output will not be simplified.
29
30### Returns
31
32Type | Description
33---- | -----------
34ConstantNode &#124; SymbolNode &#124; ParenthesisNode &#124; FunctionNode &#124; OperatorNode | The derivative of `expr`
35
36
37## Examples
38
39```js
40math.derivative('x^2', 'x') // Node {2 * x}
41math.derivative('x^2', 'x', {simplify: false}) // Node {2 * 1 * x ^ (2 - 1)
42math.derivative('sin(2x)', 'x')) // Node {2 * cos(2 * x)}
43math.derivative('2*x', 'x').evaluate() // number 2
44math.derivative('x^2', 'x').evaluate({x: 4}) // number 8
45const f = math.parse('x^2')
46const x = math.parse('x')
47math.derivative(f, x) // Node {2 * x}
48```
49
50
51## See also
52
53[simplify](simplify.md),
54[parse](parse.md),
55[evaluate](evaluate.md)