Пример #1
0
        /**
         * Checks to see all the elements in the matrix are zeros
         *
         * @param m A matrix. Not modified.
         * @return True if all elements are zeros or false if not
         */
        public static bool isZeros(CMatrixD1 m, float tol)
        {
            int length = m.getNumElements() * 2;

            for (int i = 0; i < length; i++)
            {
                if (Math.Abs(m.data[i]) > tol)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #2
0
        /**
         * <p>
         * Performs an in-place element by element scalar multiplication.<br>
         * <br>
         * a<sub>ij</sub> = &alpha;*a<sub>ij</sub>
         * </p>
         *
         * @param a The matrix that is to be scaled.  Modified.
         * @param alphaReal real component of scale factor
         * @param alphaImag imaginary component of scale factor
         */
        public static void scale(float alphaReal, float alphaImag, CMatrixD1 a)
        {
            // on very small matrices (2 by 2) the call to getNumElements() can slow it down
            // slightly compared to other libraries since it involves an extra multiplication.
            int size = a.getNumElements() * 2;

            for (int i = 0; i < size; i += 2)
            {
                float real = a.data[i];
                float imag = a.data[i + 1];

                a.data[i]     = real * alphaReal - imag * alphaImag;
                a.data[i + 1] = real * alphaImag + imag * alphaReal;
            }
        }
Пример #3
0
        /**
         * <p>
         * Checks to see if the two matrices are the negative of each other:<br>
         * <br>
         * a<sub>ij</sub> = -b<sub>ij</sub>
         * </p>
         *
         * @param a First matrix.  Not modified.
         * @param b Second matrix.  Not modified.
         * @param tol Numerical tolerance.
         * @return True if they are the negative of each other within tolerance.
         */
        public static bool isNegative(CMatrixD1 a, CMatrixD1 b, float tol)
        {
            if (a.numRows != b.numRows || a.numCols != b.numCols)
            {
                throw new ArgumentException("Matrix dimensions must match");
            }

            int length = a.getNumElements() * 2;

            for (int i = 0; i < length; i++)
            {
                if (!(Math.Abs(a.data[i] + b.data[i]) <= tol))
                {
                    return(false);
                }
            }

            return(true);
        }