.^

Element-wise power operator.

Category: Language Fundamentals > Operators and Elementary Operations

Syntax

C = A .^ B

Raises each element of A to the matching power in B. Same as power(A, B).

Description

A negative base with a non-integer exponent gives a complex result instead of NaN: (-8).^(1/3) is complex, and its real cube root is obtained with nthroot. 0.^0 is 1.

Unlike ^, which raises a square matrix to a power in the linear algebra sense, .^ always works element by element, so A.^2 squares every entry.

Input arguments

A
Base: numeric or logical array.
B
Exponent, with a size compatible with A.

Output arguments

C
Array of powers, with the size given by implicit expansion.

Example

[1 2 3] .^ 2
2 .^ [1 2 3 4]
[1 2; 3 4] .^ 2
(-8) .^ (1/3)
Output
ans = 1×3

     1     4     9
ans = 1×4

     2     4     8    16
ans = 2×2

     1     4
     9    16
ans = 1.0000 + 1.7321i

See also

power ^ sqrt nthroot exp