/** * <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); }
/** * <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); }
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); }
public static bool hasUncountable(DMatrix2 a) { if (UtilEjml.isUncountable(a.a1)) { return(true); } if (UtilEjml.isUncountable(a.a2)) { return(true); } return(false); }
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)); }
/** * <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); }
/** * <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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * <p> * Performs an in-place element by element scalar multiplication.<br> * <br> * a<sub>ij</sub> = α*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; }
/** * <p> * Performs an element by element scalar multiplication.<br> * <br> * b<sub>i</sub> = α*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; }
/** * <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; }
/** * <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; }
/** * <p>Performs the vector dot product:<br> * <br> * c = a * b <br> * <br> * c ≥ ∑<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); }
/** * <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; }
/** * <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; }
/** * <p> * Performs an element by element scalar division. Scalar denominator.<br> * <br> * b<sub>i</sub> = a<sub>i</sub> /α * </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; }
/** * <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; }
/** * <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; }
public static double fastNormF(DMatrix2 M) { double sum = M.a1 * M.a1 + M.a2 * M.a2; return(Math.Sqrt(sum)); }
/** * <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; }
/** * <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; }
/** * <p> * Performs an in-place element by element scalar division. Scalar denominator.<br> * <br> * a<sub>i</sub> = a<sub>i</sub>/α * </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; }
/** * <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; }
/** * <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; }
/** * <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; }
public static void normalizeF(DMatrix2 M) { double val = normF(M); CommonOps_DDF2.divide(M, val); }
/** * <p>Performs vector to matrix multiplication:<br> * <br> * c = a * b <br> * <br> * c<sub>j</sub> = ∑<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; }