power, .^

Symbolic array power

Description

example

A.^B computes A to the B power and is an elementwise operation.

power(A,B) is equivalent to A.^B.

Examples

Square Each Matrix Element

Create a 2-by-3 matrix.

A = sym('a', [2 3])
A =
[ a1_1, a1_2, a1_3]
[ a2_1, a2_2, a2_3]

Square each element of the matrix.

A.^2
ans =
[ a1_1^2, a1_2^2, a1_3^2]
[ a2_1^2, a2_2^2, a2_3^2]

Use Matrices for Base and Exponent

Create a 3-by-3 symbolic Hilbert matrix and a 3-by-3 diagonal matrix.

H = sym(hilb(3))
d = diag(sym([1 2 3]))
H =
[   1, 1/2, 1/3]
[ 1/2, 1/3, 1/4]
[ 1/3, 1/4, 1/5]

d =
[ 1, 0, 0]
[ 0, 2, 0]
[ 0, 0, 3]

Raise the elements of the Hilbert matrix to the powers of the diagonal matrix. The base and the exponent must be matrices of the same size.

H.^d
ans =
[ 1,   1,     1]
[ 1, 1/9,     1]
[ 1,   1, 1/125]

Input Arguments

collapse all

Input, specified as a number or a symbolic number, scalar variable, matrix variable (since R2021a), function, expression, or vector, matrix, or array of symbolic scalar variables. Inputs A and B must be the same size unless one is a scalar. A scalar value expands into an array of the same size as the other input.

Input, specified as a number or a symbolic number, scalar variable, matrix variable (since R2021a), function, expression, or vector, matrix, or array of symbolic scalar variables. Inputs A and B must be the same size unless one is a scalar. A scalar value expands into an array of the same size as the other input.