1 |
|
2 |
|
3 | # Function pow
|
4 |
|
5 | Calculates the power of x to y, `x ^ y`.
|
6 | Matrix exponentiation is supported for square matrices `x`, and positive
|
7 | integer exponents `y`.
|
8 |
|
9 | For cubic roots of negative numbers, the function returns the principal
|
10 | root by default. In order to let the function return the real root,
|
11 | math.js can be configured with `math.config({predictable: true})`.
|
12 | To retrieve all cubic roots of a value, use `math.cbrt(x, true)`.
|
13 |
|
14 |
|
15 | ## Syntax
|
16 |
|
17 | ```js
|
18 | math.pow(x, y)
|
19 | ```
|
20 |
|
21 | ### Parameters
|
22 |
|
23 | Parameter | Type | Description
|
24 | --------- | ---- | -----------
|
25 | `x` | number | BigNumber | Complex | Unit | Array | Matrix | The base
|
26 | `y` | number | BigNumber | Complex | The exponent
|
27 |
|
28 | ### Returns
|
29 |
|
30 | Type | Description
|
31 | ---- | -----------
|
32 | number | BigNumber | Complex | Array | Matrix | The value of `x` to the power `y`
|
33 |
|
34 |
|
35 | ## Examples
|
36 |
|
37 | ```js
|
38 | math.pow(2, 3) // returns number 8
|
39 |
|
40 | const a = math.complex(2, 3)
|
41 | math.pow(a, 2) // returns Complex -5 + 12i
|
42 |
|
43 | const b = [[1, 2], [4, 3]]
|
44 | math.pow(b, 2) // returns Array [[9, 8], [16, 17]]
|
45 | ```
|
46 |
|
47 |
|
48 | ## See also
|
49 |
|
50 | [multiply](multiply.md),
|
51 | [sqrt](sqrt.md),
|
52 | [cbrt](cbrt.md),
|
53 | [nthRoot](nthRoot.md)
|