power

Elementwise power, the function form of the operator .^

Category: Symbolic Computations in MATLAB > Operators and Elementary Operations

Syntax

C = power(A, B)

Same as A .^ B.

Description

Each base is raised to the matching exponent, with implicit expansion for scalars and for rows against columns. It differs from the matrix power A^2, which multiplies matrices: power([1 2; 3 4], 2) squares each entry.

A negative base with a fractional exponent gives a complex result. Integer types saturate (power(int8(10), 3) is 127), and power(0, 0) is 1.

Input arguments

A
Base: numeric array.
B
Exponent: numeric array with compatible size.

Output arguments

C
Array with A(i)^B(i) in each element.

Example

Arrays, complex results and saturation

power([1 2; 3 4], 2)
power(2, [1 2 3])
power(-8, 1/3)
power(int8(10), 3)
Output
ans = 2×2

     1     4
     9    16
ans = 1×3

     2     4     8
ans = 1.0000 + 1.7321i
ans = int8
   127

Notes

The function form with symbolic variables, as in power(x, 2), is not supported; write x.^2 or x^2 instead.

See also

mpower times sqrt nthroot