/** * <p> * Division: result = a / b * </p> * * @param a Complex number. Not modified. * @param b Complex number. Not modified. * @param result Storage for output */ public static void divide(Complex_F64 a, Complex_F64 b, Complex_F64 result) { double norm = b.getMagnitude2(); result.real = (a.real * b.real + a.imaginary * b.imaginary) / norm; result.imaginary = (a.imaginary * b.real - a.real * b.imaginary) / norm; }
/** * <p> * Unitary matrices have the following properties:<br><br> * Q*Q<sup>H</sup> = I * </p> * <p> * This is the complex equivalent of orthogonal matrix. * </p> * @param Q The matrix being tested. Not modified. * @param tol Tolerance. * @return True if it passes the test. */ public static bool isUnitary(ZMatrixRMaj Q, double tol) { if (Q.numRows < Q.numCols) { throw new ArgumentException("The number of rows must be more than or equal to the number of columns"); } Complex_F64 prod = new Complex_F64(); ZMatrixRMaj[] u = CommonOps_ZDRM.columnsToVector(Q, null); for (int i = 0; i < u.Length; i++) { ZMatrixRMaj a = u[i]; VectorVectorMult_ZDRM.innerProdH(a, a, prod); if (Math.Abs(prod.real - 1) > tol) { return(false); } if (Math.Abs(prod.imaginary) > tol) { return(false); } for (int j = i + 1; j < u.Length; j++) { VectorVectorMult_ZDRM.innerProdH(a, u[j], prod); if (!(prod.getMagnitude2() <= tol * tol)) { return(false); } } } return(true); }