示例#1
0
        /**
         * <p>
         * Returns the value of the element in the vector that has the minimum value.<br>
         * <br>
         * Min{ a<sub>i</sub> } for all<br>
         * </p>
         *
         * @param a A matrix. Not modified.
         * @return The value of element in the vector with the minimum value.
         */
        public static double elementMin(DMatrix2 a)
        {
            double min = a.a1;

            if (a.a2 < min)
            {
                min = a.a2;
            }

            return(min);
        }
示例#2
0
        /**
         * <p>
         * Returns the value of the element in the vector that has the largest value.<br>
         * <br>
         * Max{ a<sub>i</sub> } for all i<br>
         * </p>
         *
         * @param a A vector. Not modified.
         * @return The max element value of the matrix.
         */
        public static double elementMax(DMatrix2 a)
        {
            double max = a.a1;

            if (a.a2 > max)
            {
                max = a.a2;
            }

            return(max);
        }
示例#3
0
 public static bool isIdentical(DMatrix2 a, DMatrix2 b, double tol)
 {
     if (!MatrixFeatures_DDRM.isIdentical(a.a1, b.a1, tol))
     {
         return(false);
     }
     if (!MatrixFeatures_DDRM.isIdentical(a.a2, b.a2, tol))
     {
         return(false);
     }
     return(true);
 }
示例#4
0
 public static bool hasUncountable(DMatrix2 a)
 {
     if (UtilEjml.isUncountable(a.a1))
     {
         return(true);
     }
     if (UtilEjml.isUncountable(a.a2))
     {
         return(true);
     }
     return(false);
 }
示例#5
0
        public static double normF(DMatrix2 M)
        {
            double scale = CommonOps_DDF2.elementMaxAbs(M);

            if (scale == 0.0)
            {
                return(0.0);
            }

            double a1 = M.a1 / scale, a2 = M.a2 / scale;
            double sum = a1 * a1 + a2 * a2;

            return(scale * Math.Sqrt(sum));
        }
示例#6
0
        /**
         * <p>
         * Returns the absolute value of the element in the vector that has the smallest absolute value.<br>
         * <br>
         * Min{ |a<sub>i</sub>| } for all i<br>
         * </p>
         *
         * @param a A matrix. Not modified.
         * @return The max element value of the vector.
         */
        public static double elementMinAbs(DMatrix2 a)
        {
            double min = Math.Abs(a.a1);
            double tmp = Math.Abs(a.a1);

            if (tmp < min)
            {
                min = tmp;
            }
            tmp = Math.Abs(a.a2);
            if (tmp < min)
            {
                min = tmp;
            }

            return(min);
        }
示例#7
0
        /**
         * <p>
         * Returns the absolute value of the element in the vector that has the largest absolute value.<br>
         * <br>
         * Max{ |a<sub>i</sub>| } for all i<br>
         * </p>
         *
         * @param a A matrix. Not modified.
         * @return The max abs element value of the vector.
         */
        public static double elementMaxAbs(DMatrix2 a)
        {
            double max = Math.Abs(a.a1);
            double tmp = Math.Abs(a.a2);

            if (tmp > max)
            {
                max = tmp;
            }
            tmp = Math.Abs(a.a2);
            if (tmp > max)
            {
                max = tmp;
            }

            return(max);
        }
示例#8
0
        /**
         * Extracts the column from the matrix a.
         * @param a Input matrix
         * @param column Which column is to be extracted
         * @param output output. Storage for the extracted column. If null then a new vector will be returned.
         * @return The extracted column.
         */
        public static DMatrix2 extractColumn(DMatrix2x2 a, int column, DMatrix2 output)
        {
            if (output == null)
            {
                output = new DMatrix2();
            }
            switch (column)
            {
            case 0:
                output.a1 = a.a11;
                output.a2 = a.a21;
                break;

            case 1:
                output.a1 = a.a12;
                output.a2 = a.a22;
                break;

            default:
                throw new ArgumentException("Out of bounds column.  column = " + column);
            }
            return(output);
        }
示例#9
0
        /**
         * Extracts the row from the matrix a.
         * @param a Input matrix
         * @param row Which row is to be extracted
         * @param output output. Storage for the extracted row. If null then a new vector will be returned.
         * @return The extracted row.
         */
        public static DMatrix2 extractRow(DMatrix2x2 a, int row, DMatrix2 output)
        {
            if (output == null)
            {
                output = new DMatrix2();
            }
            switch (row)
            {
            case 0:
                output.a1 = a.a11;
                output.a2 = a.a12;
                break;

            case 1:
                output.a1 = a.a21;
                output.a2 = a.a22;
                break;

            default:
                throw new ArgumentException("Out of bounds row.  row = " + row);
            }
            return(output);
        }
示例#10
0
        /**
         * Converts {@link DMatrix2} into {@link DMatrixRMaj}.
         *
         * @param input Input matrix.
         * @param output Output matrix.  If null a new matrix will be declared.
         * @return Converted matrix.
         */
        public static DMatrixRMaj convert(DMatrix2 input, DMatrixRMaj output)
        {
            if (output == null)
            {
                output = new DMatrixRMaj(2, 1);
            }

            if (output.NumRows != 1 && output.NumCols != 1)
            {
                throw new ArgumentException("One row or column must have a length of 1 for it to be a vector");
            }
            int length = Math.Max(output.NumRows, output.NumCols);

            if (length != 2)
            {
                throw new ArgumentException("Length of input vector is not 2.  It is " + length);
            }

            output.data[0] = input.a1;
            output.data[1] = input.a2;

            return(output);
        }
示例#11
0
        /**
         * Converts {@link DMatrixRMaj} into {@link DMatrix2}
         *
         * @param input Input matrix.
         * @param output Output matrix.  If null a new matrix will be declared.
         * @return Converted matrix.
         */
        public static DMatrix2 convert(DMatrixRMaj input, DMatrix2 output)
        {
            if (output == null)
            {
                output = new DMatrix2();
            }

            if (input.getNumRows() != 1 && input.getNumCols() != 1)
            {
                throw new ArgumentException("One row or column must have a length of 1 for it to be a vector");
            }
            int length = Math.Max(input.getNumRows(), input.getNumCols());

            if (length != 2)
            {
                throw new ArgumentException("Length of input vector is not 2.  It is " + length);
            }

            output.a1 = input.data[0];
            output.a2 = input.data[1];

            return(output);
        }
示例#12
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 vector that is to be scaled.  Modified.
  * @param alpha the amount each element is multiplied by.
  */
 public static void scale(double alpha, DMatrix2 a)
 {
     a.a1 *= alpha;
     a.a2 *= alpha;
 }
示例#13
0
 /**
  * <p>
  * Performs an element by element scalar multiplication.<br>
  * <br>
  * b<sub>i</sub> = &alpha;*a<sub>i</sub>
  * </p>
  *
  * @param alpha the amount each element is multiplied by.
  * @param a The vector that is to be scaled.  Not modified.
  * @param b Where the scaled matrix is stored. Modified.
  */
 public static void scale(double alpha, DMatrix2 a, DMatrix2 b)
 {
     b.a1 = a.a1 * alpha;
     b.a2 = a.a2 * alpha;
 }
示例#14
0
 /**
  * <p>Performs an element by element division operation:<br>
  * <br>
  * c<sub>i</sub> = a<sub>i</sub> / b<sub>i</sub> <br>
  * </p>
  * @param a The left vector in the division operation. Not modified.
  * @param b The right vector in the division operation. Not modified.
  * @param c Where the results of the operation are stored. Modified.
  */
 public static void elementDiv(DMatrix2 a, DMatrix2 b, DMatrix2 c)
 {
     c.a1 = a.a1 / b.a1;
     c.a2 = a.a2 / b.a2;
 }
示例#15
0
 /**
  * <p>Performs the following operation:<br>
  * <br>
  * a = a + b <br>
  * a<sub>i</sub> = a<sub>i</sub> + b<sub>i</sub> <br>
  * </p>
  *
  * @param a A Vector. Modified.
  * @param b A Vector. Not modified.
  */
 public static void addEquals(DMatrix2 a, DMatrix2 b)
 {
     a.a1 += b.a1;
     a.a2 += b.a2;
 }
示例#16
0
 /**
  * <p>Performs the vector dot product:<br>
  * <br>
  * c = a * b <br>
  * <br>
  * c &ge; &sum;<sub>k=1:n</sub> { b<sub>k</sub> * a<sub>k</sub> }
  * </p>
  *
  * @param a The left vector in the multiplication operation. Not modified.
  * @param b The right matrix in the multiplication operation. Not modified.
  * @return The dot product
  */
 public static double dot(DMatrix2 a, DMatrix2 b)
 {
     return(a.a1 * b.a1 + a.a2 * b.a2);
 }
示例#17
0
 /**
  * <p>Performs an element by element division operation:<br>
  * <br>
  * a<sub>i</sub> = a<sub>i</sub> / b<sub>i</sub> <br>
  * </p>
  * @param a The left vector in the division operation. Modified.
  * @param b The right vector in the division operation. Not modified.
  */
 public static void elementDiv(DMatrix2 a, DMatrix2 b)
 {
     a.a1 /= b.a1;
     a.a2 /= b.a2;
 }
示例#18
0
 /**
  * <p>
  * Sets every element in the vector to the specified value.<br>
  * <br>
  * a<sub>i</sub> = value
  * <p>
  *
  * @param a A vector whose elements are about to be set. Modified.
  * @param v The value each element will have.
  */
 public static void fill(DMatrix2 a, double v)
 {
     a.a1 = v;
     a.a2 = v;
 }
示例#19
0
 /**
  * <p>
  * Performs an element by element scalar division.  Scalar denominator.<br>
  * <br>
  * b<sub>i</sub> = a<sub>i</sub> /&alpha;
  * </p>
  *
  * @param alpha the amount each element is divided by.
  * @param a The vector whose elements are to be divided.  Not modified.
  * @param b Where the results are stored. Modified.
  */
 public static void divide(DMatrix2 a, double alpha, DMatrix2 b)
 {
     b.a1 = a.a1 / alpha;
     b.a2 = a.a2 / alpha;
 }
示例#20
0
 /**
  * <p>Performs the following operation:<br>
  * <br>
  * a = a - b <br>
  * a<sub>i</sub> = a<sub>i</sub> - b<sub>i</sub> <br>
  * </p>
  *
  * @param a A Vector. Modified.
  * @param b A Vector. Not modified.
  */
 public static void subtractEquals(DMatrix2 a, DMatrix2 b)
 {
     a.a1 -= b.a1;
     a.a2 -= b.a2;
 }
示例#21
0
 /**
  * <p>Performs the following operation:<br>
  * <br>
  * c = a - b <br>
  * c<sub>i</sub> = a<sub>i</sub> - b<sub>i</sub> <br>
  * </p>
  *
  * <p>
  * Vector C can be the same instance as Vector A and/or B.
  * </p>
  *
  * @param a A Vector. Not modified.
  * @param b A Vector. Not modified.
  * @param c A Vector where the results are stored. Modified.
  */
 public static void subtract(DMatrix2 a, DMatrix2 b, DMatrix2 c)
 {
     c.a1 = a.a1 - b.a1;
     c.a2 = a.a2 - b.a2;
 }
示例#22
0
        public static double fastNormF(DMatrix2 M)
        {
            double sum = M.a1 * M.a1 + M.a2 * M.a2;

            return(Math.Sqrt(sum));
        }
示例#23
0
 /**
  * <p>Performs the following operation:<br>
  * <br>
  * c = a + b <br>
  * c<sub>i</sub> = a<sub>i</sub> + b<sub>i</sub> <br>
  * </p>
  *
  * <p>
  * Vector C can be the same instance as Vector A and/or B.
  * </p>
  *
  * @param a A Vector. Not modified.
  * @param b A Vector. Not modified.
  * @param c A Vector where the results are stored. Modified.
  */
 public static void add(DMatrix2 a, DMatrix2 b, DMatrix2 c)
 {
     c.a1 = a.a1 + b.a1;
     c.a2 = a.a2 + b.a2;
 }
示例#24
0
 /**
  * <p>
  * Extracts all diagonal elements from 'input' and places them inside the 'output' vector. Elements
  * are in sequential order.
  * </p>
  *
  *
  * @param input Matrix.  Not modified.
  * @param output Vector containing diagonal elements.  Modified.
  */
 public static void diag(DMatrix2x2 input, DMatrix2 output)
 {
     output.a1 = input.a11;
     output.a2 = input.a22;
 }
示例#25
0
 /**
  * <p>
  * Performs an in-place element by element scalar division. Scalar denominator.<br>
  * <br>
  * a<sub>i</sub> = a<sub>i</sub>/&alpha;
  * </p>
  *
  * @param a The vector whose elements are to be divided.  Modified.
  * @param alpha the amount each element is divided by.
  */
 public static void divide(DMatrix2 a, double alpha)
 {
     a.a1 /= alpha;
     a.a2 /= alpha;
 }
示例#26
0
 /**
  * <p>Performs an element by element multiplication operation:<br>
  * <br>
  * a<sub>i</sub> = a<sub>i</sub> * b<sub>i</sub> <br>
  * </p>
  * @param a The left vector in the multiplication operation. Modified.
  * @param b The right vector in the multiplication operation. Not modified.
  */
 public static void elementMult(DMatrix2 a, DMatrix2 b)
 {
     a.a1 *= b.a1;
     a.a2 *= b.a2;
 }
示例#27
0
 /**
  * <p>
  * Changes the sign of every element in the vector.<br>
  * <br>
  * a<sub>i</sub> = -a<sub>i</sub>
  * </p>
  *
  * @param a A vector. Modified.
  */
 public static void changeSign(DMatrix2 a)
 {
     a.a1 = -a.a1;
     a.a2 = -a.a2;
 }
示例#28
0
 /**
  * <p>Performs an element by element multiplication operation:<br>
  * <br>
  * c<sub>i</sub> = a<sub>i</sub> * b<sub>j</sub> <br>
  * </p>
  * @param a The left vector in the multiplication operation. Not modified.
  * @param b The right vector in the multiplication operation. Not modified.
  * @param c Where the results of the operation are stored. Modified.
  */
 public static void elementMult(DMatrix2 a, DMatrix2 b, DMatrix2 c)
 {
     c.a1 = a.a1 * b.a1;
     c.a2 = a.a2 * b.a2;
 }
示例#29
0
        public static void normalizeF(DMatrix2 M)
        {
            double val = normF(M);

            CommonOps_DDF2.divide(M, val);
        }
示例#30
0
 /**
  * <p>Performs vector to matrix multiplication:<br>
  * <br>
  * c = a * b <br>
  * <br>
  * c<sub>j</sub> = &sum;<sub>k=1:n</sub> { b<sub>k</sub> * a<sub>kj</sub> }
  * </p>
  *
  * @param a The left vector in the multiplication operation. Not modified.
  * @param b The right matrix in the multiplication operation. Not modified.
  * @param c Where the results of the operation are stored. Modified.
  */
 public static void mult(DMatrix2 a, DMatrix2x2 b, DMatrix2 c)
 {
     c.a1 = a.a1 * b.a11 + a.a2 * b.a21;
     c.a2 = a.a1 * b.a12 + a.a2 * b.a22;
 }