# mpower, ^

## Syntax

• `C = A^B` example
• `C = mpower(A,B)`

## Description

example

````C = A^B` computes `A` to the `B` power and returns the result in `C`.```
````C = mpower(A,B)` is an alternate way to execute `A^B`, but is rarely used. It enables operator overloading for classes.```

## Examples

collapse all

### Square a Matrix

Create a 2-by-2 matrix and square it.

```A = [1 2; 3 4]; C = A^2```
```C = 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 = 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 = -0.7071 0.7071 0.7071 0.7071 D = -1 0 0 1```

Next, use the formula `2^B = V*2^D/V` to compute the power.

`C = V*2^D/V`
```C = 1.2500 0.7500 0.7500 1.2500```

## Input Arguments

collapse all

### `A` — Basescalar | matrix

Base, specified as a scalar or matrix. Inputs `A` and `B` must be one of the following:

• Base `A` is a square matrix and exponent `B` is a scalar. If `B` is a positive integer, the power is computed by repeated squaring. For other values of `B` the calculation involves eigenvalues and eigenvectors.

• Base `A` is a scalar and exponent `B` is a square matrix. The calculation uses eigenvalues and eigenvectors.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `logical` | `char`
Complex Number Support: Yes

### `B` — Exponentscalar | matrix

Exponent, specified as a scalar or matrix. Inputs `A` and `B` must be one of the following:

• Base `A` is a square matrix and exponent `B` is a scalar. If `B` is a positive integer, the power is computed by repeated squaring. For other values of `B` the calculation involves eigenvalues and eigenvectors.

• Base `A` is a scalar and exponent `B` is a square matrix. The calculation uses eigenvalues and eigenvectors.

Data Types: `single` | `double` | `int8` | `int16` | `int32` | `int64` | `uint8` | `uint16` | `uint32` | `uint64` | `logical` | `char`
Complex Number Support: Yes