An Objective-C class that performs basic Linear Algebra Matrix (learn more here) operations, such as:
- Addition
- Subtraction
- Multiplication
- Multiplication by a scalar
- Transposition
I've been teaching myself Objective-C since I was 15 and recently I entered university to study Computer Science. Among all the available subjects, the one that I'm liking the most (besides programming) is Linear Algebra and Analytic Geometry so I decided to combine my Objective-C skills with what I'm learning in university and try to simulate an Algebra Matrix class.
General Features:
This class was designed to work somewhat like a NSArray
, in terms of how you perform certain operations, so you can do stuff like:
- Retrieve the number of rows / columns of the matrix (like you would do with
NSArray
'scount
) - Add/Insert a new row/columm
- Remove a row/column
- Retrieve an entire row/column (in a
NSArray
) - Retrieve an element from the matrix (at a specific row and column)
- Replace a especific element with a new one
Specific Linear Algebra Matrix Features:
- Retrieve the main diagonal elements (in a
NSArray
) - Check if the matrix is a Row / Column vector
- Check if the matrix is a Null / Empty / Square / Identity / Diagonal / Triangular matrix
- Check if two matrices are equal
- Add both .h and .m files of
PVAlgebraMatrix
into your project. - Import
PVAlgebraMatrix.h
to wherever you want to use it just by#import "PVAlgebraMatrix.h"
- You're ready to start creating your own Matrices and kickass!
There are several ways of creating Matrices. You could just "alloc init" a PVAlgebraMatrix
object to create an empty Matrix (0 rows and columns, with no elements) and add rows / columns as you wish, or you could create a default Matrix type (Identity or Null) in just one line of code.
PVAlgebraMatrix *identityMatrix = [PVAlgebraMatrix identityMatrixWithSize:5];
PVAlgebraMatrix *nullMatrix = [PVAlgebraMatrix nullMatrixWithRows:5 columns:5];
PVAlgebraMatrix *defaultValuesMatrix = [[PVAlgebraMatrix alloc] initWithRows:4 columns:5 setDefaultValueForAllElements:5];
PVAlgebraMatrix *customMatrix = [[PVAlgebraMatrix alloc] init];
[customMatrix addRowFromArray:@[@2,@3,@4]];
[customMatrix addRowFromArray:@[@5,@6,@7]];
[customMatrix addRowFromArray:@[@8,@9,@0]];
[customMatrix addColumnFromArray:@[@1,@1,@1]];
PVAlgebraMatrix was created by Pedro Vieira.
@w1tch_
[email protected]
Check "LICENSE" to know more.