public static MatrixF One(int rows, int columns) { MatrixF m = new MatrixF(rows, columns); for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { m[r, c] = 1.0f; } } return(m); }
public MatrixF Transpose() { MatrixF t = new MatrixF(Columns, Rows); for (int r = 0, rows = Rows; r < rows; r++) { for (int c = 0, cols = Columns; c < cols; c++) { t[c, r] = _matrix[r, c]; } } return(t); }
public static MatrixF operator *(float d, MatrixF a) { MatrixF x = a.Clone(); for (int r = 0, rows = x.Rows; r < rows; r++) { for (int c = 0, cols = x.Columns; c < cols; c++) { x[r, c] *= d; } } return(x); }
public static MatrixF operator -(MatrixF a) { MatrixF x = a.Clone(); for (int r = 0, rows = a.Rows; r < rows; r++) { for (int c = 0, cols = a.Columns; c < cols; c++) { x[r, c] = -x[r, c]; } } return(x); }
public static MatrixF Identity(int dimensions) { MatrixF m = new MatrixF(dimensions, dimensions); for (int r = 0, rows = dimensions; r < rows; r++) { for (int c = 0, cols = dimensions; c < cols; c++) { m[r, c] = (r == c) ? 1.0f : 0.0f; } } return(m); }
public MatrixF Invert() { int rows = Rows; int cols = Columns; if (rows != cols) { throw new InvalidOperationException("Unable to invert non-square matrix"); } if (Determinant == 0.0f) { throw new InvalidOperationException("Unable to invert matrix where determinant equals 0"); } MatrixF x = Clone(); float e; for (int k = 0; k < rows; k++) { e = x[k, k]; x[k, k] = 1.0f; for (int j = 0; j < cols; j++) { x[k, j] = x[k, j] / e; } for (int i = 0; i < cols; i++) { if (i != k) { e = x[i, k]; x[i, k] = 0.0f; for (int j = 0; j < cols; j++) { x[i, j] = x[i, j] - e * x[k, j]; } } } } return(x); }
public static MatrixF operator -(MatrixF a, MatrixF b) { if (a.Rows != b.Rows || a.Columns != b.Columns) { throw new ArgumentException("Unable to subtract matrices of different dimensions"); } MatrixF x = a.Clone(); for (int r = 0, rows = x.Rows; r < rows; r++) { for (int c = 0, cols = x.Columns; c < cols; c++) { x[r, c] -= b[r, c]; } } return(x); }
public static MatrixF operator *(MatrixF a, MatrixF b) { if (a.Columns != b.Rows) throw new ArgumentException("Unable to multiply matrices of different inner dimensions"); MatrixF x = new MatrixF(a.Rows, b.Columns); int inner = a.Columns; for (int r = 0, rows = x.Rows; r < rows; r++) { for (int c = 0, cols = x.Columns; c < cols; c++) { float d = 0.0f; for (int i = 0; i < inner; i++) d += a[r, i] * b[i, c]; x[r, c] = d; } } return x; }
public static MatrixF Identity(int dimensions) { MatrixF m = new MatrixF(dimensions, dimensions); for (int r = 0, rows = dimensions; r < rows; r++) { for (int c = 0, cols = dimensions; c < cols; c++) { m[r, c] = (r == c) ? 1.0f : 0.0f; } } return m; }
public static MatrixF One(int rows, int columns) { MatrixF m = new MatrixF(rows, columns); for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { m[r, c] = 1.0f; } } return m; }
public MatrixF Transpose() { MatrixF t = new MatrixF(Columns, Rows); for (int r = 0, rows = Rows; r < rows; r++) { for (int c = 0, cols = Columns; c < cols; c++) { t[c, r] = _matrix[r, c]; } } return t; }