1 |
|
2 |
|
3 | # Function derivative
|
4 |
|
5 | Takes the derivative of an expression expressed in parser Nodes.
|
6 | The derivative will be taken over the supplied variable in the
|
7 | second parameter. If there are multiple variables in the expression,
|
8 | it will return a partial derivative.
|
9 |
|
10 | This 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
|
18 | derivative(expr, variable)
|
19 | derivative(expr, variable, options)
|
20 | ```
|
21 |
|
22 | ### Parameters
|
23 |
|
24 | Parameter | Type | Description
|
25 | --------- | ---- | -----------
|
26 | `expr` | Node | string | The expression to differentiate
|
27 | `variable` | SymbolNode | 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 |
|
32 | Type | Description
|
33 | ---- | -----------
|
34 | ConstantNode | SymbolNode | ParenthesisNode | FunctionNode | OperatorNode | The derivative of `expr`
|
35 |
|
36 |
|
37 | ## Examples
|
38 |
|
39 | ```js
|
40 | math.derivative('x^2', 'x') // Node {2 * x}
|
41 | math.derivative('x^2', 'x', {simplify: false}) // Node {2 * 1 * x ^ (2 - 1)
|
42 | math.derivative('sin(2x)', 'x')) // Node {2 * cos(2 * x)}
|
43 | math.derivative('2*x', 'x').evaluate() // number 2
|
44 | math.derivative('x^2', 'x').evaluate({x: 4}) // number 8
|
45 | const f = math.parse('x^2')
|
46 | const x = math.parse('x')
|
47 | math.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)
|