1 |
|
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 | ## Examples
|
32 |
|
33 | ```js
|
34 | math.abs(-3.5) // returns 3.5
|
35 | math.norm(-3.5) // returns 3.5
|
36 |
|
37 | math.norm(math.complex(3, -4)) // returns 5
|
38 |
|
39 | math.norm([1, 2, -3], Infinity) // returns 3
|
40 | math.norm([1, 2, -3], -Infinity) // returns 1
|
41 |
|
42 | math.norm([3, 4], 2) // returns 5
|
43 |
|
44 | math.norm([[1, 2], [3, 4]], 1) // returns 6
|
45 | math.norm([[1, 2], [3, 4]], 'inf') // returns 7
|
46 | math.norm([[1, 2], [3, 4]], 'fro') // returns 5.477225575051661
|
47 | ```
|
48 |
|
49 |
|
50 | ## See also
|
51 |
|
52 | [abs](abs.md),
|
53 | [hypot](hypot.md)
|