Class MatrixOperations
- Namespace
- SignalSharp.Utilities
- Assembly
- SignalSharp.dll
Provides operations for matrix manipulation and arithmetic.
The class includes methods to transpose matrices and perform matrix multiplication.
public static class MatrixOperations
- Inheritance
-
MatrixOperations
- Inherited Members
Methods
Inverse(double[,])
Inverts the given matrix.
The method uses the Gauss-Jordan elimination method to compute the inverse of a matrix.
public static double[,] Inverse(double[,] matrix)
Parameters
matrix
double[,]The matrix to invert.
Returns
- double[,]
The inverse of the matrix.
Examples
double[,] matrix = { {1, 2}, {3, 4} };
double[,] result = MatrixOperations.Inverse(matrix);
// result is { {-2, 1}, {1.5, -0.5} }
Exceptions
- ArgumentException
Thrown when the matrix is not square or is singular (non-invertible).
Multiply(double[,], double[,])
Multiplies two matrices and returns the result.
Matrix multiplication is only defined when the number of columns in the first matrix matches the number of rows in the second matrix.
public static double[,] Multiply(double[,] A, double[,] B)
Parameters
Returns
- double[,]
The product of the two matrices.
Examples
double[,] A = { {1, 2}, {3, 4} };
double[,] B = { {5, 6}, {7, 8} };
double[,] result = MatrixOperations.Multiply(A, B);
// result is { {19, 22}, {43, 50} }
Exceptions
- ArgumentException
Thrown when the number of columns in A does not match the number of rows in B.
Multiply(double[,], double[])
Multiplies a matrix by a vector and returns the result.
This operation is defined when the number of columns in the matrix matches the length of the vector.
public static double[] Multiply(double[,] A, double[] B)
Parameters
Returns
- double[]
The product of the matrix and the vector.
Examples
double[,] A = { {1, 2}, {3, 4}, {5, 6} };
double[] B = { 7, 8 };
double[] result = MatrixOperations.Multiply(A, B);
// result is { 23, 53, 83 }
Exceptions
- ArgumentException
Thrown when the number of columns in the matrix does not match the length of the vector.
SolveLinearSystemQR(double[,], double[])
Solves a system of linear equations Ax = b using QR factorization with SIMD optimization.
public static double[] SolveLinearSystemQR(double[,] A, double[] y)
Parameters
A
double[,]The matrix representing the system of linear equations.
y
double[]The vector representing the right-hand side of the equations.
Returns
- double[]
An array of solutions for the system of linear equations.
Examples
double[,] A = { { 1, 2 }, { 3, 4 } };
double[] y = { 5, 6 };
double[] result = SolveLinearSystemQR(A, y);
Transpose(double[,])
Transposes the given matrix.
The transpose of a matrix is obtained by swapping its rows with its columns.
public static double[,] Transpose(double[,] matrix)
Parameters
matrix
double[,]The matrix to transpose.
Returns
- double[,]
The transposed matrix.
Examples
double[,] matrix = { {1, 2}, {3, 4}, {5, 6} };
double[,] result = MatrixOperations.Transpose(matrix);
// result is { {1, 3, 5}, {2, 4, 6} }
TrySolveLinearSystemQR(double[,], double[], out double[]?)
public static bool TrySolveLinearSystemQR(double[,] A, double[] y, out double[]? solution)