derivative.md (1776B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 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 ### Throws 38 39 Type | Description 40 ---- | ----------- 41 42 43 ## Examples 44 45 ```js 46 math.derivative('x^2', 'x') // Node {2 * x} 47 math.derivative('x^2', 'x', {simplify: false}) // Node {2 * 1 * x ^ (2 - 1) 48 math.derivative('sin(2x)', 'x')) // Node {2 * cos(2 * x)} 49 math.derivative('2*x', 'x').evaluate() // number 2 50 math.derivative('x^2', 'x').evaluate({x: 4}) // number 8 51 const f = math.parse('x^2') 52 const x = math.parse('x') 53 math.derivative(f, x) // Node {2 * x} 54 ``` 55 56 57 ## See also 58 59 [simplify](simplify.md), 60 [parse](parse.md), 61 [evaluate](evaluate.md)