Download the PHP package busybrain/matrix without Composer
On this page you can find all versions of the php package busybrain/matrix. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download busybrain/matrix
More information about busybrain/matrix
Files in busybrain/matrix
Package matrix
Short Description a simple php library for playing with matrices
License MIT
Informations about the package matrix
Looking at this 2 years after i wrote this code and i am only glad at the progress i have made :)
A simple, fluent and stable PHP library for playing around with matrices
SIMPLE PHP LIBRARY FOR PLAYING WITH MATRICES
The focus of this project is simplicity, beautiful syntax and speed. It allows you work seemlessly with matrices in php. It comes with a handful of methods that you can use to write your own matrix logics
Getting started
You can create an instance of the class using the new keyword and immediately call the set mathod which sets a matrix value into the class ready for manipulation. Each matrix instance must be a multidimensional array.
you can as well use the static make method on the matrix class. this recieves a matrix instance as an argument and does exactly the same thing as the previous code retruning an instance of the class created
you can also set scalar values for operations that require scalar values using the set scalar method. The library allows chaining methods.
identity matrix
You can create an identity matrix by simply using the identity matrix method in the matrix class
conver scalar to matrix
you can convert a scalar to an n by m matrix using the scalarToMatrix method
operations
the library currently support the following operations and is still being worked on for others
- Addition ----------------------- add
- subtraction -------------------- subtract
- Multiplication -----------------multiply
- Determinant----------------------det
- Transpose------------------------ transpose
You can use each one by first setting up the matrix with all the parameters needed then calling their endpoint on it.
Except for the detrminant where the result is a scalar, other operations gives an instance of the matrix class when the endpoint is called as a method instead of as a property. Hence we can chain multiple operations together. When you call the setScalar method on the addition or subtraction operation, the scalar would be converted to marix and included in the operation
Other methods
There are a handful of methods that can give you details about a matrix . You can call them all on the matrix instance.
Validation
you can run valiation on a matrix against a set of attributes using the validate method . The validation options currently supported are
dim:row,col ------- checks if the matrix dimension matches the option given square --------- checks if the matrix is a square matrix singualr ------- checks if the matrix is a singular matrix
you can also write closure based validations . it takes two arguments, first is the matrix being validated while the second is a function that is called when the validation returns false to pass the appropriate validation message
the validate method returns a boolean result. For debugging purpose, the package also has a method that returns the validation errors. use validateWithMessage instead
the method returns an array of the validation errors. An empty array is returned if the validation passes