# 幂和指数

### 正整数幂

```A = [1 1 1 1 2 3 1 3 6]; A^2```
```ans = 3×3 3 6 10 6 14 25 10 25 46 ```

### 逆幂和分数幂

`A^(-3)`
```ans = 3×3 145.0000 -207.0000 81.0000 -207.0000 298.0000 -117.0000 81.0000 -117.0000 46.0000 ```

MATLAB® 用相同的算法计算 `inv(A)``A^(-1)`，因此结果完全相同。如果矩阵接近奇异，`inv(A)``A^(-1)` 都会发出警告。

`isequal(inv(A),A^(-1))`
```ans = logical 1 ```

`A^(2/3)`
```ans = 3×3 0.8901 0.5882 0.3684 0.5882 1.2035 1.3799 0.3684 1.3799 3.1167 ```

### 逐元素幂

`.^` 运算符计算逐元素幂。例如，要对矩阵中的每个元素求平方，可以使用 `A.^2`

`A.^2`
```ans = 3×3 1 1 1 1 4 9 1 9 36 ```

### 平方根

`sqrt(A)`
```ans = 3×3 1.0000 1.0000 1.0000 1.0000 1.4142 1.7321 1.0000 1.7321 2.4495 ```

`nthroot(A,3)`
```ans = 3×3 1.0000 1.0000 1.0000 1.0000 1.2599 1.4422 1.0000 1.4422 1.8171 ```

`B = sqrtm(A)`
```B = 3×3 0.8775 0.4387 0.1937 0.4387 1.0099 0.8874 0.1937 0.8874 2.2749 ```
`B^2`
```ans = 3×3 1.0000 1.0000 1.0000 1.0000 2.0000 3.0000 1.0000 3.0000 6.0000 ```

### 标量底

`2^A`
```ans = 3×3 10.4630 21.6602 38.5862 21.6602 53.2807 94.6010 38.5862 94.6010 173.7734 ```

```[V,D] = eig(A); V*2^D*V^(-1)```
```ans = 3×3 10.4630 21.6602 38.5862 21.6602 53.2807 94.6010 38.5862 94.6010 173.7734 ```

### 矩阵指数

```e = exp(1); e^A```
```ans = 3×3 103 × 0.1008 0.2407 0.4368 0.2407 0.5867 1.0654 0.4368 1.0654 1.9418 ```

`expm` 函数是计算矩阵指数的一种更方便的方法。

`expm(A)`
```ans = 3×3 103 × 0.1008 0.2407 0.4368 0.2407 0.5867 1.0654 0.4368 1.0654 1.9418 ```

### 处理较小的数字

`log(1+eps/2)`
```ans = 0 ```

`log1p(eps/2)`
```ans = 1.1102e-16 ```

`exp(eps/2)-1`
```ans = 0 ```

`expm1(eps/2)`
```ans = 1.1102e-16 ```