power, .^
Element-wise power
Syntax
Description
C = raises
each element of A.^BA to the corresponding powers in
B. The sizes of A and
B must be the same or be compatible.
If the sizes of A and B are compatible,
then the two arrays implicitly expand to match each other. For example, if one
of A or B is a scalar, then the scalar is
combined with each element of the other array. Also, vectors with different
orientations (one row vector and one column vector) implicitly expand to form a
matrix.
Examples
Input Arguments
More About
Tips
Using
timesor.*for repeated multiplications can be faster than usingpoweror.^with integer exponents. However, round-off errors are greater with repeated multiplications because the errors accumulate. This is particularly important for thedoubledata type. For data types where round-off errors are not an issue, such asint64, you can usetimes. For example, if you definex = int64(randi([1, 10], 10000, 1));, then the operationy = x.*x.*x;is faster thany = x.^3;.