Search code examples
swiftcomplex-numbersaccelerate-frameworkexponentiation

Raising a complex number (__CLPK_complex) to an exponent in the Accelerate Framework


I am doing some matrix operations in Swift and I am using the Accelerate framework to do so. I need to be able to find matrix powers efficiently. To do that I diagonalise a matrix by finding its eigenvalues and eigenvectors (using the dgeev_ function) and then I need to raise the eigenvalues to the power in question. I am storing the eigenvalues as a __CLPK_complex type which is provided in Accelerate.

How do I raise a value of this type to power provided as Double?


Solution

  • I ended up creating a wrapper and a protocol to represent complex numbers and extended __CLPK_complex to conform to it. I then implemented the ^ operator and used De Moivre's Theorem to calculate the desired power.