isHermitianMatrix method

bool isHermitianMatrix({
  1. num tolerance = 1e-10,
})

Checks if the matrix is Hermitian (equal to its conjugate transpose). Returns true if the matrix is Hermitian, false otherwise.

Parameters:

  • tolerance (optional, default = 1e-10): The tolerance used to check for equality of elements.

Implementation

bool isHermitianMatrix({num tolerance = 1e-10}) {
  if (!isSquareMatrix()) {
    return false;
  }

  int n = rowCount;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      Complex conjugateValue;
      if (this[j][i] is Complex) {
        conjugateValue = this[j][i].conjugate;
      } else {
        conjugateValue = this[j][i];
      }

      if ((this[i][j] - conjugateValue).abs() > tolerance) {
        return false;
      }
    }
  }

  return true;
}