Example #1
0
        public static MatrixF operator +(MatrixF _m1, MatrixF _m2)
        {
            if (_m1.n != _m2.n || _m1.m != _m2.m)
            {
                return(null);
            }

            // Add the two matrices
            MatrixF m = new MatrixF(_m1.n, _m1.m);

            for (int i = 0; i < _m1.n; i++)
            {
                for (int j = 0; j < _m1.m; j++)
                {
                    m.data[i, j] = _m1.data[i, j] + _m2.data[i, j];
                }
            }
            return(m);
        }
Example #2
0
        public static MatrixF DotProduct(MatrixF _m1, MatrixF _m2)
        {
            if (_m1.m != _m2.n)
            {
                return(null);
            }

            MatrixF m = new MatrixF(_m1.n, _m2.m);

            for (int i = 0; i < m.n; i++)
            {
                for (int j = 0; j < m.m; j++)
                {
                    float sum = 0;
                    for (int k = 0; k < _m1.m; k++)
                    {
                        sum += _m1.data[i, k] * _m2.data[k, j];
                    }
                    m.data[i, j] = sum;
                }
            }
            return(m);
        }