// Inverse of the matrix ComplexMatrix3D ComplexMatrix3D::inv() const { Complex determinant; ComplexMatrix3D inv; determinant = this->det(); if(determinant.mod() < Math::TOLERANCE) return *this; inv.r[0] = (this->r[4]*this->r[8] - this->r[5]*this->r[7])/determinant; inv.r[3] = ((this->r[5]*this->r[6] - this->r[3]*this->r[8])/determinant); inv.r[6] = ((this->r[3]*this->r[7] - this->r[4]*this->r[6])/determinant); inv.r[1] = ((this->r[7]*this->r[2] - this->r[8]*this->r[1])/determinant); inv.r[4] = (this->r[8]*this->r[0] - this->r[6]*this->r[2])/determinant; inv.r[7] = ((this->r[6]*this->r[1] - this->r[7]*this->r[0])/determinant); inv.r[2] = ((this->r[1]*this->r[5] - this->r[2]*this->r[4])/determinant); inv.r[5] = ((this->r[2]*this->r[3] - this->r[0]*this->r[5])/determinant); inv.r[8] = (this->r[0]*this->r[4] - this->r[1]*this->r[3])/determinant; return(inv); }
Php::Value div(Php::Parameters ¶ms) { Php::Value t = params[0]; Complex *b = (Complex*) t.implementation(); double t1 = b->mod() * b->mod(); if (t1 < EPS) throw Php::Exception("Division by zero"); double tr = r * (double) (b->getReal()) + i * (double) (b->getImage()); double ti = i * (double) (b->getReal()) - r * (double) (b->getImage()); r = tr / t1; i = ti / t1; return this; }
// Principal log Complex log(const Complex & a) { double theta = a.arg(); if ((theta / PI) > 1.0 || (theta / PI) < -1.0) { theta = theta - floor(theta / PI) * PI; } Complex temp(log(a.mod()), a.arg()); return temp; }
Complex Complex::operator/(const Complex & a) const { return Complex(*this * a.cc()) / sqr(a.mod()); }