mpower, ^
Matrix power
Syntax
Description
Examples
Square a Matrix
Create a 2-by-2 matrix and square it.
A = [1 2; 3 4]; C = A^2
C = 2×2
7 10
15 22
The syntax A^2
is equivalent to A*A
.
Matrix Exponents
Create a 2-by-2 matrix and use it as the exponent for a scalar.
B = [0 1; 1 0]; C = 2^B
C = 2×2
1.2500 0.7500
0.7500 1.2500
Compute C
by first finding the eigenvalues D
and eigenvectors V
of the matrix B
.
[V,D] = eig(B)
V = 2×2
-0.7071 0.7071
0.7071 0.7071
D = 2×2
-1 0
0 1
Next, use the formula 2^B = V*2^D/V
to compute the power.
C = V*2^D/V
C = 2×2
1.2500 0.7500
0.7500 1.2500
Input Arguments
A
, B
— Operands
scalar | matrix
Operands, specified as scalars or matrices. Inputs A
and B
must be one of the following combinations:
Base
A
and exponentB
are both scalars, in which caseA^B
is equivalent toA.^B
.Base
A
is a square matrix and exponentB
is a scalar. IfB
is a positive integer, the power is computed by repeated squaring. For other values ofB
the calculation uses an eigenvalue decomposition (for most matrices) or a Schur decomposition (for defective matrices).Base
A
is a scalar and exponentB
is a square matrix. The calculation uses an eigenvalue decomposition.
Operands with an integer data type cannot be complex.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| char
Complex Number Support: Yes
Tips
MATLAB® computes
X^(-1)
andinv(X)
in the same manner, and both are subject to the same limitations. For more information, seeinv
.
References
[1] Higham, Nicholas J., and Lijing Lin. “An Improved Schur--Padé Algorithm for Fractional Powers of a Matrix and Their Fréchet Derivatives.” SIAM Journal on Matrix Analysis and Applications 34, no. 3 (January 2013): 1341–1360. https://doi.org/10.1137/130906118.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
If
A
is a 2-by-2 or larger matrix andB
isInf
or-Inf
, thenA^B
returns a matrix ofNaN
values.For
A^b
, ifb
is a noninteger scalar, then at least one ofA
orb
must be complex.Code generation does not support sparse matrix inputs for this function.
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
Usage notes and limitations:
If
A
is a 2-by-2 or larger matrix andB
isInf
or-Inf
, thenA^B
returns a matrix ofNaN
values.For
A^b
, ifb
is a noninteger scalar, then at least one ofA
orb
must be complex.Code generation does not support sparse matrix inputs for this function.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
Both inputs must be scalar, and the exponent input, k
, must be
an integer.
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
The mpower
function
supports GPU array input with these usage notes and limitations:
If base
A
is a sparse matrix, exponentB
must be a nonnegative real integer.If
A
is a sparse scalar,B
must be a scalar.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced before R2006aR2021b: Improved algorithm for defective matrices
The algorithm for defective matrices raised to a real power was improved. In
previous releases, mpower
used an algorithm based on eigenvalue
decomposition for these inputs that can return incorrect results for defective
matrices. The new algorithm for defective matrices is instead based on the Schur
decomposition.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)