mpower — Raise a scalar or square matrix to a power.
mpower(A, B) is the callable form of A ^ B and implements scalar exponentiation plus repeated matrix products for supported integer matrix exponents.
Syntax
C = mpower(A, B)Inputs
A- Type
Any- Required
- Yes
- Description
- Left numeric, logical, character, complex, or provider-resident operand.
B- Type
Any- Required
- Yes
- Description
- Right numeric, logical, character, complex, or provider-resident operand.
Returns
C- Type
NumericArray- Description
- Matrix-arithmetic result.
Errors
RunMat:mpower:InvalidArgument- When
- The exponent is not a supported scalar value.
- Message
mpower: invalid exponent
RunMat:mpower:InvalidInput- When
- The base is unsupported, a matrix base is not square, or a negative floating matrix power requires a singular inverse.
- Message
mpower: unsupported operand types
RunMat:mpower:Internal- When
- Runtime cannot complete a provider operation or materialize its output.
- Message
mpower: internal runtime failure
Scalar and matrix powers
mpower(A, B) and A ^ B raise a scalar or square matrix base to a scalar power. Scalar bases use ordinary numeric exponentiation. A nonscalar base must be square and currently requires an integer-valued exponent.
A zero matrix exponent returns an identity matrix with the base's size and floating class. Positive integer matrix exponents use binary exponentiation, reducing the number of matrix products.
Classes and domains
Real and complex scalar bases follow scalar power domain rules. Complex matrices use complex matrix products. Square fixed-width integer matrices support nonnegative integer-valued scalar exponents, preserve the base class, and use saturating multiply-accumulate operations.
Real and complex single/double matrices support negative integer powers. The inverse uses the same host kernel as inv; larger negative powers use binary exponentiation of that inverse. Singular matrices return an input error. Fixed-width integer matrix bases still require a nonnegative exponent.
Acceleration
For supported nonnegative powers of a provider-resident matrix, identity construction and each product use the exact owner. Temporary handles are released after their last use, and the final handle cannot alias an input or consumed temporary.
Negative floating matrix powers use the shared host inverse path and return the result to the original provider. Other unsupported forms or typed unsupported-operation responses may select the documented host fallback. Operational provider errors and invalid output metadata are reported.
Examples
Raise a matrix to an integer power
A = [1 3; 2 4];
C = A ^ 2Expected output:
C = [7 15; 10 22]Return the identity for exponent zero
A = [5 2; 7 1];
I = mpower(A, 0)Expected output:
I = eye(2)Raise a scalar to a fractional power
r = mpower(4, 0.5)Expected output:
r = 2Reject a fractional matrix exponent
A = [1 2; 3 4];
C = mpower(A, 1.5)Expected output:
Matrix power requires integer exponent.Compute a matrix power on a provider
G = gpuArray(single([2 0; 0 2]));
H = mpower(G, 3);
R = gather(H)Expected output:
R = single([8 0; 0 8])Using mpower with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how mpower changes the result.
Run a small mpower example, explain the result, then change one input and compare the output.
FAQ
Does mpower support nonsquare matrices?⌄
No. Use element-wise power, written .^, when matrix-product semantics are not intended.
Can a matrix exponent be fractional?⌄
Not currently. Nonscalar bases require an integer-valued exponent.
Are negative matrix exponents supported?⌄
Yes for real or complex single/double matrices. They use the shared inverse kernel and retain the floating class. Fixed-width integer matrix bases require nonnegative powers.
How does mpower differ from power?⌄
mpower composes matrix products. power raises corresponding elements independently.
Will results stay provider-resident?⌄
Yes when the exact owner supports every required identity and matrix-product operation. A typed unsupported response selects the documented fallback.
What exponent range is accepted for matrix bases?⌄
The current runtime accepts integer-valued exponents representable as signed 32-bit values.
Related Linalg functions
Ops
cross · ctranspose · dot · mldivide · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Source you can read
Every RunMat function's source is public. Read exactly how mpower is executed, line by line, in Rust.
- View the source for mpower in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.