示例#1
0
        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");
            }
        }
示例#2
0
        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);
        }
示例#3
0
 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];
         }
     }
 }
示例#4
0
 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);
 }
示例#5
0
        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();
            }
        }
示例#6
0
 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");
     }
 }