2017 © Pedro Peláez
 

library php-matrix

Matrix basic implementation.

image

vermotr/php-matrix

Matrix basic implementation.

  • Tuesday, December 1, 2015
  • by vermotr
  • Repository
  • 1 Watchers
  • 1 Stars
  • 102 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 3 % Grown

The README.md

Matrix

Matrix basic implementation., (*1)

Installation

composer require vermotr/php-matrix:0.1.0

Alternatively you can add the following to the require section of your composer.json manually:, (*2)

"vermotr/php-matrix": "0.1.0"

Usage

There are three ways to instantiate a matrix:, (*3)

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);

You can access each element like a bi-dimensional array and display the matrix like so:, (*4)

$matrix[4][2] = 42;

echo $matrix;

To know the matrix' size, you have access to two getters:, (*5)

$matrix->getRows();
$matrix->getCols();

In this class, you will find basic operations: add, subtract and multiply (by scalars and Matrices):, (*6)

$addedScalar = $matrix->add(4);
$addedMatrix = $matrix->add($anotherMatrix);
$subtractedScalar = $matrix->subtract(2);
$subtractedMatrix = $matrix->subtract($anotherMatrix);
$multipliedByScalar = $matrix->multiply(2);
$multipliedByMatrix = $matrix->multiply($anotherMatrix);

You can also compare two matrices with the equals method:, (*7)

if ($matrix1->equals($matrix2)) {
    // Do something!
}

There are some useful methods implemented in this class:, (*8)

$matrix->adjugate();
$matrix->cofactor();
$matrix->determinant();
$matrix->inverse();
$matrix->subMatrix();
$matrix->transpose();

Changelog

  • 0.1.0
    • Created the Matrix type
    • Scalar Addition
    • Matrix Addition
    • Scalar Subtraction
    • Matrix Subtraction
    • Scalar Multiplication
    • Matrix Multiplication
    • Adjugate
    • Cofactor
    • Determinant
    • Inverse
    • Submatrix
    • Transpose

The Versions

01/12 2015

dev-master

9999999-dev

Matrix basic implementation.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Romain Vermot

math matrix linear-algebra

01/12 2015

0.1.0

0.1.0.0

Matrix basic implementation.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Romain Vermot

math matrix linear-algebra