UNPKG

1.36 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function norm
4
5Calculate the norm of a number, vector or matrix.
6
7The second parameter p is optional. If not provided, it defaults to 2.
8
9
10## Syntax
11
12```js
13math.norm(x)
14math.norm(x, p)
15```
16
17### Parameters
18
19Parameter | Type | Description
20--------- | ---- | -----------
21`x` | number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Value for which to calculate the norm
22`p` | number &#124; BigNumber &#124; 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
26Type | Description
27---- | -----------
28number &#124; BigNumber | the p-norm
29
30
31## Examples
32
33```js
34math.abs(-3.5) // returns 3.5
35math.norm(-3.5) // returns 3.5
36
37math.norm(math.complex(3, -4)) // returns 5
38
39math.norm([1, 2, -3], Infinity) // returns 3
40math.norm([1, 2, -3], -Infinity) // returns 1
41
42math.norm([3, 4], 2) // returns 5
43
44math.norm([[1, 2], [3, 4]], 1) // returns 6
45math.norm([[1, 2], [3, 4]], 'inf') // returns 7
46math.norm([[1, 2], [3, 4]], 'fro') // returns 5.477225575051661
47```
48
49
50## See also
51
52[abs](abs.md),
53[hypot](hypot.md)