PHPackages                             mykola-ivashchuk-gl/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. mykola-ivashchuk-gl/matrix

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

mykola-ivashchuk-gl/matrix
==========================

PHP Class for working with matrices supporting PHP 5.5.9

2.1.1(5y ago)011MITPHPPHP ^7.1 || ^8.0

Since Aug 12Pushed 5y agoCompare

[ Source](https://github.com/mykola-ivashchuk-gl/PHPMatrix)[ Packagist](https://packagist.org/packages/mykola-ivashchuk-gl/matrix)[ Docs](https://github.com/MarkBaker/PHPMatrix)[ RSS](/packages/mykola-ivashchuk-gl-matrix/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (1)Dependencies (8)Versions (19)Used By (0)

PHPMatrix
=========

[](#phpmatrix)

What was changed?
-----------------

[](#what-was-changed)

Added support for PHP 5.5.9

---

PHP Class for handling Matrices

Master: [![Build Status](https://camo.githubusercontent.com/b8b9622185909329312d3a0c915d9a5658d58835c91174ca35db4d7a50754400/68747470733a2f2f7472617669732d63692e6f72672f4d61726b42616b65722f5048504d61747269782e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/MarkBaker/PHPMatrix)

Develop: [![Build Status](https://camo.githubusercontent.com/597f891029dc98b69a0a3972ac27d54758aa94e19f64d290099eab32501d10c5/68747470733a2f2f7472617669732d63692e6f72672f4d61726b42616b65722f5048504d61747269782e706e673f6272616e63683d646576656c6f70)](http://travis-ci.org/MarkBaker/PHPMatrix)

[![Matrix Transform](https://camo.githubusercontent.com/5d1c707d0b5c59abe708d5777be252504850b9e4fc41f4ba83451fba7578c5cf/68747470733a2f2f696d67732e786b63642e636f6d2f636f6d6963732f6d61747269785f7472616e73666f726d2e706e67)](https://xkcd.com/184/)

Matrix Transform

---

This library currently provides the following operations:

- addition
- direct sum
- subtraction
- multiplication
- division (using \[A\].\[B\]-1)
    - division by
    - division into

together with functions for

- adjoint
- antidiagonal
- cofactors
- determinant
- diagonal
- identity
- inverse
- minors
- trace
- transpose

TO DO
-----

[](#to-do)

- power()
- EigenValues
- EigenVectors
- Decomposition

---

Usage
=====

[](#usage)

To create a new Matrix object, provide an array as the constructor argument

```
$grid = [
    [16,  3,  2, 13],
    [ 5, 10, 11,  8],
    [ 9,  6,  7, 12],
    [ 4, 15, 14,  1],
];

$matrix = new Matrix\Matrix($grid);

```

The `Builder` class provides helper methods for creating specific matrices, specifically an identity matrix of a specified size; or a matrix of a specified dimensions, with every cell containing a set value.

```
$matrix = new Matrix\Builder::createFilledMatrix(1, 5, 3);

```

Will create a matrix of 5 rows and 3 columns, filled with a `1` in every cell; while

```
$matrix = new Matrix\Builder::createIdentityMatrix(3);

```

will create a 3x3 identity matrix.

Matrix objects are immutable: whenever you call a method or pass a grid to a function that returns a matrix value, a new Matrix object will be returned, and the original will remain unchanged. This also allows you to chain multiple methods as you would for a fluent interface (as long as they are methods that will return a Matrix result).

Performing Mathematical Operations
----------------------------------

[](#performing-mathematical-operations)

To perform mathematical operations with Matrices, you can call the appropriate method against a matrix value, passing other values as arguments

```
$matrix1 = new Matrix([
    [2, 7, 6],
    [9, 5, 1],
    [4, 3, 8],
]);
$matrix2 = new Matrix([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
]);

echo $matrix1->multiply($matrix2);

```

or pass all values to the appropriate function

```
$matrix1 = new Matrix([
    [2, 7, 6],
    [9, 5, 1],
    [4, 3, 8],
]);
$matrix2 = new Matrix([
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
]);

echo Matrix\multiply($matrix1, $matrix2);

```

You can pass in the arguments as Matrix objects, or as arrays.

If you want to perform the same operation against multiple values (e.g. to add three or more matrices), then you can pass multiple arguments to any of the operations.

Using functions
---------------

[](#using-functions)

When calling any of the available functions for a matrix value, you can either call the relevant method for the Matrix object

```
$grid = [
    [16,  3,  2, 13],
    [ 5, 10, 11,  8],
    [ 9,  6,  7, 12],
    [ 4, 15, 14,  1],
];

$matrix = new Matrix\Matrix($grid);

echo $matrix->trace();

```

or you can call the function as you would in procedural code, passing the Matrix object as an argument

```
$grid = [
    [16,  3,  2, 13],
    [ 5, 10, 11,  8],
    [ 9,  6,  7, 12],
    [ 4, 15, 14,  1],
];

$matrix = new Matrix\Matrix($grid);
echo Matrix\trace($matrix);

```

When called procedurally using the function, you can pass in the argument as a Matrix object, or as an array.

```
$grid = [
    [16,  3,  2, 13],
    [ 5, 10, 11,  8],
    [ 9,  6,  7, 12],
    [ 4, 15, 14,  1],
];

echo Matrix\trace($grid);

```

As an alternative, it is also possible to call the method directly from the `Functions` class.

```
$grid = [
    [16,  3,  2, 13],
    [ 5, 10, 11,  8],
    [ 9,  6,  7, 12],
    [ 4, 15, 14,  1],
];

$matrix = new Matrix\Matrix($grid);
echo Matrix\Functions::trace($matrix);

```

Used this way, methods must be called statically, and the argument must be the Matrix object, and cannot be an array.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~56 days

Recently: every ~1 days

Total

17

Last Release

1934d ago

Major Versions

0.2.0 → 1.0.02018-08-12

1.2.0 → 2.0.02020-08-28

1.2.1 → 2.1.02021-01-20

1.2.2 → 2.1.12021-01-21

PHP version history (4 changes)0.1.0PHP ^5.6.0|^7.0.0

2.0.0PHP ^7.2 || ^8.0

2.1.0PHP ^7.1 || ^8.0

1.3.0PHP ^5.5.9|^7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/15cced701d409e0e42c113709bf93733bb0c7032c9267e7f8331de8f19582238?d=identicon)[Mykola Ivashchuk](/maintainers/Mykola%20Ivashchuk)

---

Top Contributors

[![mykola-ivashchuk-gl](https://avatars.githubusercontent.com/u/75077777?v=4)](https://github.com/mykola-ivashchuk-gl "mykola-ivashchuk-gl (4 commits)")

---

Tags

mathematicsvectormatrix

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/mykola-ivashchuk-gl-matrix/health.svg)

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

###  Alternatives

[markbaker/matrix

PHP Class for working with matrices

1.5k279.7M38](/packages/markbaker-matrix)[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M277](/packages/brick-math)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[markbaker/complex

PHP Class for working with complex numbers

1.7k283.1M38](/packages/markbaker-complex)[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2751.4M5](/packages/rubix-tensor)[spicyweb/craft-neo

A Matrix-like field type with block hierarchy

395798.1k10](/packages/spicyweb-craft-neo)

PHPackages © 2026

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