PHPackages                             leonickl/matrix - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. leonickl/matrix

ActiveProject[Utility &amp; Helpers](/categories/utility)

leonickl/matrix
===============

v2.3.1(5mo ago)09PHPPHP &gt;=8.4

Since Dec 12Pushed 5mo agoCompare

[ Source](https://github.com/leonickl/php-matrix)[ Packagist](https://packagist.org/packages/leonickl/matrix)[ RSS](/packages/leonickl-matrix/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (17)Used By (0)

Matrix
======

[](#matrix)

A PHP package incorporating basic matrix algebra. Examples can be found in `playground.php`.

Installation
------------

[](#installation)

```
composer require leonickl/matrix
```

Usage
-----

[](#usage)

Matrices are instances of `Matrix` and can be defined either via the class' constructor or the `matrix()` helper function.

```
// define a matrix
$A = matrix([
    [5, 8, 6, 3],
    [7, 9, 1, 3],
    [2, 6, 8, 7],
    [6, 0, 5, 7],
]);

// invert matrix
$A->invert();

// calculate determinant
$A->det();

// transpose matrix
$A->transpose(); // or ->t()

// multiply with another matrix B
$A->times($B);

// add two matrices
$A->plus($B); // or ->minus($B) for subtraction

// scalar multiplication
$A->scalar(2);
```

A `Matrix` can be converted to a `Vector` object if it has only one column or only one row. A vector is always a matrix of dimension $(n \\times 1)$ and offers further methods, while a `Vector` is still treated as a `Matrix`. Vectors can be also created instantly by their constructor or the `vector` helper, of course.

```
// convert a matrix to a vector
$C->vector(); // works if C is of dimension (1⨉n) or (n⨉1)

// define a vector
$c = vector([1, 5, 7, 4]);

// multiply transposed c to A
$c->t()->times($A);

// inner (dot) product of c with itself (c'c)
$c->inner($c);

// outer product of c with itself (cc'), generating a (n⨉n) matrix
$c->outer($c);

// plus, minus, scalar, times work the same
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance72

Regular maintenance activity

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity60

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

16

Last Release

155d ago

Major Versions

v1.7.0 → v2.0.02025-12-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/e4a0fefacbd2c15d86300c8c7e91f040b6f09b0e6a8699ff741051ee7e97329e?d=identicon)[leonickl](/maintainers/leonickl)

### Embed Badge

![Health badge](/badges/leonickl-matrix/health.svg)

```
[![Health](https://phpackages.com/badges/leonickl-matrix/health.svg)](https://phpackages.com/packages/leonickl-matrix)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
