vermotr / php-matrix
矩阵基本实现。
0.1.0
2015-12-01 09:44 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-09-18 18:58:42 UTC
README
矩阵基本实现。
安装
composer require vermotr/php-matrix:0.1.0
或者,您可以手动将以下内容添加到composer.json文件的require部分
"vermotr/php-matrix": "0.1.0"
用法
有三种方式可以实例化一个矩阵
use vermotr\Math\Matrix; // Create a Matrix with its size $matrix = new Matrix(4, 2); // With a bi-dimensional array $matrix = new Matrix([ [0, 1, 2], [3, 4, 5], [6, 7, 8] ]); // With another Matrix $matrix = new Matrix($anotherMatrix);
您可以将每个元素访问为一个二维数组,并按如下方式显示矩阵
$matrix[4][2] = 42;
echo $matrix;
要了解矩阵的大小,您可以访问两个getter方法
$matrix->getRows(); $matrix->getCols();
在这个类中,您可以找到基本操作:加、减和乘(标量和矩阵)
$addedScalar = $matrix->add(4); $addedMatrix = $matrix->add($anotherMatrix); $subtractedScalar = $matrix->subtract(2); $subtractedMatrix = $matrix->subtract($anotherMatrix); $multipliedByScalar = $matrix->multiply(2); $multipliedByMatrix = $matrix->multiply($anotherMatrix);
您还可以使用equals方法比较两个矩阵
if ($matrix1->equals($matrix2)) { // Do something! }
在这个类中实现了一些有用的方法
$matrix->adjugate(); $matrix->cofactor(); $matrix->determinant(); $matrix->inverse(); $matrix->subMatrix(); $matrix->transpose();
变更日志
- 0.1.0
- 创建Matrix类型
- 标量加法
- 矩阵加法
- 标量减法
- 矩阵减法
- 标量乘法
- 矩阵乘法
- 伴随矩阵
- 余子式
- 行列式
- 逆矩阵
- 子矩阵
- 转置