public static double[,] Multiply(Matrixs a, Matrixs b) { int m = a.Rows(); int n = a.Cols(); int p = b.Rows(); int q = b.Cols(); if (n == p) { double[,] c = new double[m, q]; for (var i = 0; i < m; i++) { for (var j = 0; j < q; j++) { c[i, j] = 0; for (int k = 0; k < n; k++) { c[i, j] += a.Data()[i, k] * b.Data()[k, j]; } } } return(c); } else { throw new System.ArgumentException("Matrices dimensions do not match for multiply", "matrix"); } }
public static Matrixs FromArray(int [] array) { var m = new Matrixs(array.GetLength(0), 1); for (int i = 0; i < array.GetLength(0); i++) { m.Data()[i, 0] = array[i]; } return(m); }
public void Add(Matrixs n) { for (var i = 0; i < Rows(); i++) { for (var j = 0; j < Cols(); j++) { matrix[i, j] += n.Data()[i, j]; } } }
public static double[] ToArray(Matrixs matrix) { double[] arr = new double[matrix.Rows() + matrix.Cols()]; for (int i = 0; i < matrix.Rows(); i++) { for (int j = 0; j < matrix.Cols(); j++) { arr[i] = matrix.Data()[i, j]; } } return(arr); }
public static void DisplayMatrix(Matrixs a) { int m = a.Rows(); int n = a.Cols(); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { Console.Write(a.Data()[i, j] + " "); } Console.WriteLine(); } }
public static Matrixs Add(Matrixs a, Matrixs b) { if (SubtractableDimensions(a, b)) { for (var i = 0; i < a.Rows(); i++) { for (var j = 0; j < a.Cols(); j++) { a.Data()[i, j] += b.Data()[i, j]; } } return(a); } else { throw new System.ArgumentException("Matrices dimensions do not match for substraction"); } }