From e662c7bebdc8db9ff7b6079a29a44169735fba2b Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Mon, 18 Jul 2022 15:40:33 +0200 Subject: [PATCH] Add identity matrix and check for eigenvalue --- matrix.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/matrix.hpp b/matrix.hpp index d64c240..2016ca6 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -108,6 +108,22 @@ public: const matrix hermitian_conjugate() const { return this->transpose().conjugate(); } + const matrix I() const { + matrix m = matrix(this->num_entries, this->entry_dimension); + for (long long i = 0; i < this->num_entries; i++) { + for (long long j = 0; j < this->entry_dimension; j++) { + if (i == j) { + m[i][j] = cnumber(1, 0); + } else { + m[i][j] = 0; + } + } + } + return m; + } + const bool is_eigenvalue(cnumber z) const { + return ((*this - (this->I() * z)).determinant() == 0); + } const bool is_hermitian() const { if (this->entry_dimension != this->num_entries) return false;