/** * <p> * x<sup>T</sup>A<sup>T</sup>y * </p> * * @param x A vector with n elements. Not modified. * @param A A matrix with n by n elements. Not modified. * @param y A vector with n elements. Not modified. * @return The results. */ // TODO better name for this public static double innerProdTranA(DMatrixD1 x, DMatrixD1 A, DMatrixD1 y) { int n = A.numRows; if (n != A.numCols) { throw new ArgumentException("A must be square"); } if (x.NumElements != n) { throw new ArgumentException("Unexpected number of elements in x"); } if (y.NumElements != n) { throw new ArgumentException("Unexpected number of elements in y"); } double result = 0; for (int i = 0; i < n; i++) { double total = 0; for (int j = 0; j < n; j++) { total += x.get(j) * A.unsafe_get(i, j); } result += total * y.get(i); } return(result); }
/** * <p> * return = x<sup>T</sup>*A*y * </p> * * @param x A vector with n elements. Not modified. * @param A A matrix with n by m elements. Not modified. * @param y A vector with m elements. Not modified. * @return The results. */ public static double innerProdA(DMatrixD1 x, DMatrixD1 A, DMatrixD1 y) { int n = A.numRows; int m = A.numCols; if (x.getNumElements() != n) { throw new ArgumentException("Unexpected number of elements in x"); } if (y.getNumElements() != m) { throw new ArgumentException("Unexpected number of elements in y"); } double result = 0; for (int i = 0; i < m; i++) { double total = 0; for (int j = 0; j < n; j++) { total += x.get(j) * A.unsafe_get(j, i); } result += total * y.get(i); } return(result); }
/** * Computes the quality of a triangular matrix, where the quality of a matrix * is defined in {@link LinearSolverDense#quality()}. In * this situation the quality os the absolute value of the product of * each diagonal element divided by the magnitude of the largest diagonal element. * If all diagonal elements are zero then zero is returned. * * @param T A matrix. * @return the quality of the system. */ public static double qualityTriangular(DMatrixD1 T) { int N = Math.Min(T.numRows, T.numCols); // TODO make faster by just checking the upper triangular portion double max = elementDiagonalMaxAbs(T); if (max == 0.0) { return(0.0); } double quality = 1.0; for (int i = 0; i < N; i++) { quality *= T.unsafe_get(i, i) / max; } return(Math.Abs(quality)); }