函数 pow #

计算 x 的 y 次幂,即 x ^ y

支持方阵 x 和整数 y 的矩阵指数运算:当 y 为非负数时,x 可以是任意方阵;当 y 为负数时,x 必须是可逆的,此时函数返回 inv(x)^(-y)。

对于负数的立方根,该函数默认返回主根。要使函数返回实数根,可以将 math.js 配置为 math.config({predictable: true})。要获取某个值的全部立方根,请使用 math.cbrt(x, true)

Syntax #

math.pow(x, y)

Parameters #

Parameter Type Description
x number | BigNumber | bigint | Complex | Unit | Array | Matrix 基数
y number | BigNumber | bigint | Complex 指数

Returns #

Type Description
number | BigNumber | bigint | Complex | Array | Matrix xy 次幂的值

Throws #

Type | Description —- | ———–

Examples #

math.pow(2, 3)               // returns number 8

const a = math.complex(2, 3)
math.pow(a, 2)                // returns Complex -5 + 12i

const b = [[1, 2], [4, 3]]
math.pow(b, 2)               // returns Array [[9, 8], [16, 17]]

const c = [[1, 2], [4, 3]]
math.pow(c, -1)               // returns Array [[-0.6, 0.4], [0.8, -0.2]]

另请参阅 #

multiply, sqrt, cbrt, nthRoot

Fork me on GitHub