C# Library for Matrices
MathExtended.Matrix is project by Ales Hotko and was first released in April 2018. It's licensed under the MIT license.
//Create square matrix of size 3x3
Matrix matrix = new Matrix(3);
//Create matrix of any size (i.e. 5x3)
Matrix matrix = new Matrix(5, 3);
Matrix zero = Matrix.Zero(rows, cols);
//..or..
Matrix zeroSquare = Matrix.Zero(size);
Matrix identity = Matrix.Identity(size);
//Populate Matrix
matrix[1, 1] = 5.0;
matrix[1, 2] = 5.0;
matrix[1, 3] = 5.0;
//...or populate with random values between -5.0 and 10.0
matrix.Randomize(-5,0, 10.0);
//..or with random values between 0 and 1
matrix.Randomize();
Matrix a = new Matrix(3, 3);
Matrix b = new Matrix(3, 3);
Matrix sum = a + b;
//..or..
a.Add(b);
Matrix diff = a - b;
//..or..
a.Add(b);
//multiplication with scalar
Matrix product = a * 3.0;
//..or..
a.Multiply(3.0);
//multiplication with another matrix
Matrix product = a * b;
//..or..
a.Multiply(b);
a.HadamardProduct(b);
Matrix inverse = !a;
//..or..
a.Inverse();
Matrix r = new Matrix(5, 4);
r.Transpose();
Matrix r = new Matrix(5, 4);
r.Map(Math.Sin); //Apply Sine function to every matrix element
//or own function
public double MyFunction(double param)
{
return param * 42.0;
}
//[...]
r.Map(MyFunction);
//[...]
//Equality
if(a == b) {}
//..or..
if(a != b) {}
//..or..
if(a > b) {}
//..or..
if(a < b) {}
//..or..
if(a >= b) {}
//..or..
if(a <= b) {}
//2D
Matrix rotation2D = Matrix.Rotation2D(angleInDegrees);
//3D around X, Y or Z axis
Matrix rotation3D = Matrix.Rotation3DX(angleInDegrees);
Matrix rotation3D = Matrix.Rotation3DY(angleInDegrees);
Matrix rotation3D = Matrix.Rotation3DZ(angleInDegrees);
Matrix scaling = Matrix.Scaling(factorX, factorY, factorZ);
Matrix translation = Matrix.Translation(moveX, moveY, moveZ);