Matrix is a framework written in Objective C that helps in performing mathematical calculations of multidimensional matrices. It also contains the matrix print functionality, for better visualization.
Can be used in both Objective C and Swift.
- In your project click: File -> Swift Packages -> Add Package Dependency...
- Then, paste https://github.com/ronaldogomes96/Matrix
- Choice Next
- Make sure you choose the branch main
1 - Import Matrix framework
import Matrix
2 - Create Matrix Calculator object
let matrix = MatrixCalculator()
3 - Use some of the functions given in the documentation
OBS: It's important to note that all functions take arrays of multiple dimensions.
Therefore examples like the following generate an error:
matrix.meanMatrix([1, 2, 3], axis: total) // One-Dimensional Matrix
They should look like this:
matrix.meanMatrix([[1, 2, 3]], axis: total) // Multi-Dimensional Matrix
Performs sum between two matrices.
let mat1 = [[10.2, 18.5],
[11.3, -3.2]]
let mat2 = [[1.6, 0.2],
[3.9, -9.0]]
let sum = matrix.sumMatrix(mat1, toMatrix: mat2)
Performs subtraction between two matrices.
let mat1 = [[10.2, 18.5],
[11.3, -3.2]]
let mat2 = [[1.6, 0.2],
[3.9, -9.0]]
let subtraction = matrix.subtractionMatrix(mat2, toMatrix: mat1)
Performs matrix multiplication by a scalar number.
Let number = 7.3
let mat1 = [[10.2, 18.5],
[11.3, -3.2]]
let multiply = matrix.multiplyMatrix(mat1, toScalar: number)
We have three possibilities for calculating the matrix mean, for the x, y axes and the total matrix mean.
We specify x in the axis parameter
let mat1 = [[10.2, 18.5],
[11.3, -3.2]]
let meanX = matrix.meanMatrix(mat1, axis: x)
We specify y in the axis parameter
let mat1 = [[10.2, 18.5],
[11.3, -3.2]]
let meanY = matrix.meanMatrix(mat1, axis: y)
We specify total in the axis parameter
let mat1 = [[10.2, 18.5],
[11.3, -3.2]]
let meanTotal = matrix.meanMatrix(mat1, axis: total)
We have a function that prints the matrix more pleasantly on the terminal with row and column information
let mat1 = [[10.2, 18.5],
[11.3, -3.2]]
matrix.printMatrix(mat1)
If you want to contribute just open an issue informing the improvement or create a pull request.
Give a ⭐️ if this project helped you!
Copyright © 2021 Ronaldo Gomes Jéssica Guiot
Matrix is available under the MIT license. See the LICENSE file for more info.