norm.md (1414B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function norm 4 5 Calculate the norm of a number, vector or matrix. 6 7 The second parameter p is optional. If not provided, it defaults to 2. 8 9 10 ## Syntax 11 12 ```js 13 math.norm(x) 14 math.norm(x, p) 15 ``` 16 17 ### Parameters 18 19 Parameter | Type | Description 20 --------- | ---- | ----------- 21 `x` | number | BigNumber | Complex | Array | Matrix | Value for which to calculate the norm 22 `p` | number | BigNumber | string | Vector space. Supported numbers include Infinity and -Infinity. Supported strings are: 'inf', '-inf', and 'fro' (The Frobenius norm) Default value: 2. 23 24 ### Returns 25 26 Type | Description 27 ---- | ----------- 28 number | BigNumber | the p-norm 29 30 31 ### Throws 32 33 Type | Description 34 ---- | ----------- 35 36 37 ## Examples 38 39 ```js 40 math.abs(-3.5) // returns 3.5 41 math.norm(-3.5) // returns 3.5 42 43 math.norm(math.complex(3, -4)) // returns 5 44 45 math.norm([1, 2, -3], Infinity) // returns 3 46 math.norm([1, 2, -3], -Infinity) // returns 1 47 48 math.norm([3, 4], 2) // returns 5 49 50 math.norm([[1, 2], [3, 4]], 1) // returns 6 51 math.norm([[1, 2], [3, 4]], 'inf') // returns 7 52 math.norm([[1, 2], [3, 4]], 'fro') // returns 5.477225575051661 53 ``` 54 55 56 ## See also 57 58 [abs](abs.md), 59 [hypot](hypot.md)