## 矩阵
> 将PHP数组包装到数学矩阵的类。
### 创建
要创建Matrix,请使用简单数组:
```
$matrix = new Matrix([
[3, 3, 3],
[4, 2, 1],
[5, 6, 7],
]);
```
您还可以从平面阵列创建Matrix(一维):
```
$flatArray = [1, 2, 3, 4];
$matrix = Matrix::fromFlatArray($flatArray);
```
*****
### 矩阵数据
从`Matrix`读取数据的方法:
```
$matrix->toArray(); // cast matrix to PHP array
$matrix->getRows(); // rows count
$matrix->getColumns(); // columns count
$matrix->getColumnValues($column=4); // get values from given column
```
*****
### 行列式
阅读有关[矩阵行列式](https://baike.baidu.com/item/%E7%9F%A9%E9%98%B5%E8%A1%8C%E5%88%97%E5%BC%8F/18882017?fr=aladdin)的更多信息
```
$matrix = new Matrix([
[3, 3, 3],
[4, 2, 1],
[5, 6, 7],
]);
$matrix->getDeterminant();
// return -3
```
*****
### 颠倒
阅读有关[矩阵转置](https://baike.baidu.com/item/%E7%9F%A9%E9%98%B5%E8%BD%AC%E7%BD%AE/4150715?fr=aladdin)的更多信息。
```
$matrix->transpose();
// return new Matrix
```
*****
### 乘
由另一个矩阵乘以矩阵。
```
$matrix1 = new Matrix([
[1, 2, 3],
[4, 5, 6],
]);
$matrix2 = new Matrix([
[7, 8],
[9, 10],
[11, 12],
]);
$matrix1->multiply($matrix2);
// result $product = [
// [58, 64],
// [139, 154],
//];
```
*****
### 除以标量
您可以通过标量值划分`Matrix`。
```
$matrix->divideByScalar(2);
```
*****
### 逆
阅读有关[可逆矩阵](https://baike.baidu.com/item/%E5%8F%AF%E9%80%86%E7%9F%A9%E9%98%B5/11035614)的更多信息
```
$matrix = new Matrix([
[3, 4, 2],
[4, 5, 5],
[1, 1, 1],
]);
$matrix->inverse();
// result $inverseMatrix = [
// [0, -1, 5],
// [1 / 2, 1 / 2, -7 / 2],
// [-1 / 2, 1 / 2, -1 / 2],
//];
```
*****
### 划出
从`Matrix`中划出给定的行和列。
```
$matrix = new Matrix([
[3, 4, 2],
[4, 5, 5],
[1, 1, 1],
]);
$matrix->crossOut(1, 1)
// result $crossOuted = [
// [3, 2],
// [1, 1],
//];
```