PHP Classes

PHP Matrix Math Library: Perform operations to manipulate matrices

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 96 All time: 9,858 This week: 48Up
Version License PHP version Categories
php-maths-matrix 1.0.0GNU General Publi...5PHP 5, Data types, Math
Description 

Author

This class can perform operations to manipulate matrices

It can take bi-dimensional arrays with numbers as parameters and can perform several types of matrix operations. Currently it can:

- Multiply two matrices
- Divide two matrices by inverting one matrix and multiplying by another
- Invert a matrix
- Add or subtract two matrices
- Transpose a matrix
- Display a matrix in a HTML page
- Check if a matrix is squared
- Find the determinant of a matrix
- Find the adjunct matrix
- Calculate a matrix co-factor
- Calculate a matrix minor
- Solve an equation given two matrices of factors

Picture of Clement Sam
  Performance   Level  
Name: Clement Sam is available for providing paid consulting. Contact Clement Sam .
Classes: 4 packages by
Country: Ghana Ghana
Age: 26
All time rank: 29422 in Ghana Ghana
Week rank: 214 Up3 in Ghana Ghana Down
Innovation award
Innovation award
Nominee: 1x

Recommendations

Perform matrix arithmetic
I need to compute determinats

Example

<?php
include 'matrix.class.php';

$matrix1 = [
    [
1,2,3,3],
    [
2,3,6,3],
    [
4,7,6,3]
];
$matrix2 = [
    [
1,2,1],
    [
2,1,2],
    [
1,2,3],
];

$matrix3 = [
    [
1,2,3],
    [
2,3,6],
    [
2,3,6],
];

$matrix4 = [
    [
1,2,3],
    [
2,3,6],
    [
2,3,6]
];

$matrix5 = [
    [
4,1],
    [
3,2]
];

$matrix6 = [
    [
1,3,2],
    [
4,1,3],
    [
2,5,2]
];

$Matrix = new Matrix;
$Matrix->displayAs("matrix");
$mul = $Matrix->multiply($matrix2, $matrix3);
$add = $Matrix->add($matrix2, $matrix3);
$sub = $Matrix->subtract($matrix2, $matrix3);

echo
"Transpose of Matrix 1 <br/>";
echo(
$Matrix->transpose($matrix1));
echo
"Transpose of Matrix 2 <br/>";
echo(
$Matrix->transpose($matrix2));
echo
"Transpose of Matrix 3 <br/>";
echo(
$Matrix->transpose($matrix3));
echo
"Transpose of Matrix 4 <br/>";
echo(
$Matrix->transpose($matrix4));


echo
"multiplication of Matrices <br/>";
print_r($mul);

echo
"Addition of Matrices <br/>";
print_r($add);

echo
"determinant of Matrix 6 <br/>";
print_r($Matrix->determinant($matrix6));
echo
"<br/>";

echo
"Minor of Matrix 5 <br/>";
print_r($Matrix->minor($matrix5));

echo
"Cofactor of Matrix 5 <br/>";
print_r($Matrix->cofactor($matrix5));

echo
"Adjoint of Matrix 5 <br/>";
print_r($Matrix->adjoint($matrix5));

echo
"Inverse of Matrix 5 <br/>";
print_r($Matrix->inverse($matrix5));

echo
"Dividing Matrix 2 by Matrix 2... We should get an identity matrix <br/>";
print_r($Matrix->divide($matrix5, $matrix5));
?>


<style type="text/css">
    .matrix td {
        text-align: center;
    }
    .inl_block {
        display: inline-block;
    }
    .v_align_middle {
        vertical-align: middle;
    }
    .pad10 {
        padding: 10px;
    }
    .matrix {
        position: relative;
    }
    .matrix:before, .matrix:after {
        content: "";
        position: absolute;
        top: 0;
        border: 1px solid #000;
        width: 6px;
        height: 100%;
    }
    .matrix:before {
        left: -6px;
        border-right: 0;
    }
    .matrix:after {
        right: -6px;
        border-left: 0;
    }

    .mat
</style>


Details

PHP Matrix Maths Library

This class can perform operations to manipulate matrices

It can take bi-dimensional arrays with numbers as parameters and can perform several types of matrix operations. Currently it can:

  • Multiply two matrices
  • Divide two matrices by inverting one matrix and multiplying by another
  • Invert a matrix
  • Add or subtract two matrices
  • Transpose a matrix
  • Display a matrix in a HTML page
  • Check if a matrix is squared
  • Find the determinant of a matrix
  • Find the adjunct matrix
  • Calculate a matrix co-factor
  • Calculate a matrix minor
  • Solve an equation given two matrices of factors

Demo & Usage

php-maths-matrix.herokuapp.com


  PHP Maths Matrix Demo PageExternal page  

Open in a separate window

  Files folder image Files (4)  
File Role Description
Accessible without login Plain text file index.php Example Example script
Plain text file matrix.class.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file test.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:96
This week:0
All time:9,858
This week:48Up