Theoretica
A C++ numerical and automatic mathematical library
theoretica::phasor< Type > Class Template Reference

Complex number in exponential form \(\rho e^{i \theta}\). More...

#include <phasor.h>

Public Member Functions

 phasor ()
 Initialize as 0/0.
 
 phasor (Type modulus, Type phase)
 Initialize from two real numbers.
 
 phasor (const phasor &other)
 Initialize from another phasor.
 
template<typename T >
 phasor (const complex< T > &z)
 Construct a phasor from a complex number.
 
 phasor (Type r)
 Construct a phasor from a real number.
 
phasoroperator= (const phasor &z)
 Assignment operator.
 
template<typename T >
phasoroperator= (const std::array< T, 2 > &v)
 Assignment operator from a 2D array as {modulus, phase}.
 
Type Re () const
 Get the real part of the complex number.
 
Type Im () const
 Get the imaginary part of the complex number.
 
phasor conjugate () const
 Compute the conjugate of the complex number.
 
Type sqr_norm () const
 Compute the square norm of the complex number.
 
Type norm () const
 Compute the norm of the complex number.
 
Type inverse () const
 Compute the inverse of the complex number.
 
phasorinvert ()
 Invert the complex number.
 
Type arg () const
 Get the argument of the complex number.
 
phasor operator+ (const phasor &other) const
 Add two phasors. More...
 
phasor operator- (const phasor &other) const
 Subtract two phasors. More...
 
phasor operator* (const phasor &other) const
 Multiply two phasors.
 
template<typename T >
phasor operator* (const complex< T > &other) const
 Multiply a complex number in algebraic form and a phasor.
 
phasor operator/ (const phasor &other) const
 Divide two phasors.
 
phasoroperator+= (const phasor &other)
 Add a phasor to this one.
 
phasoroperator-= (const phasor &other)
 Subtract a phasor from this one.
 
phasoroperator*= (const phasor &other)
 Multiply this phasor by another one.
 
phasoroperator/= (const phasor &other)
 Divide this phasor by another one.
 
bool operator== (const phasor &z) const
 Check whether two phasors are the same.
 
bool operator!= (const phasor &z) const
 Check whether two phasors are not the same.
 
template<typename T = Type>
complex< T > to_complex () const
 Transform a phasor to a complex number.
 
template<typename T >
 operator complex< T > ()
 Cast to complex.
 
std::string to_string (const std::string &separator=", ") const
 Convert the phasor to string representation.
 
 operator std::string ()
 Convert the phasor to string representation.
 

Static Public Member Functions

static phasor rotor (Type rad)
 Construct a phasor representing a rotation of <rad> radians in 2 dimensions.
 
static phasor i ()
 Imaginary unit in exponential form.
 

Public Attributes

Type modulus
 Modulus of the complex number.
 
Type phase
 Phase of the complex number.
 

Friends

Type Re (const phasor &z)
 Extract the real part of the complex number.
 
Type Im (const phasor &z)
 Extract the imaginary part of the complex number.
 
template<typename T >
phasor operator* (const complex< T > &z, const phasor &w)
 Multiply a complex number in algebraic form and a phasor.
 
phasor operator+ (Type r, const phasor &z)
 
phasor operator- (Type r, const phasor &z)
 
phasor operator* (Type r, const phasor &z)
 
phasor operator/ (Type r, const phasor &z)
 
std::ostream & operator<< (std::ostream &out, const phasor &obj)
 Stream the phasor in string representation to an output stream (std::ostream)
 

Detailed Description

template<typename Type = real>
class theoretica::phasor< Type >

Complex number in exponential form \(\rho e^{i \theta}\).

Member Function Documentation

◆ operator+()

template<typename Type = real>
phasor theoretica::phasor< Type >::operator+ ( const phasor< Type > &  other) const
inline

Add two phasors.

Note
This operation is particularly slow for phasors as opposed to complex numbers in algebraic form.

◆ operator-()

template<typename Type = real>
phasor theoretica::phasor< Type >::operator- ( const phasor< Type > &  other) const
inline

Subtract two phasors.

Note
This operation is particularly slow for phasors as opposed to complex numbers in algebraic form.

The documentation for this class was generated from the following file: