math-php
Public Member Functions | Public Attributes | Protected Attributes | List of all members
MathPHP\Number\Complex Class Reference

Class: Complex Complex Numbers. More...

Inheritance diagram for MathPHP\Number\Complex:
Inheritance graph
[legend]
Collaboration diagram for MathPHP\Number\Complex:
Collaboration graph
[legend]

Public Member Functions

 __construct ($r, $i)
 Constructor: __construct. More...
 
 __toString ()
 Function: __toString String representation of a complex number a + bi, a - bi, etc. More...
 
 __get (string $part)
 Function: __get Get r or i. More...
 
 complexConjugate ()
 The conjugate of a complex number. More...
 
 abs ()
 The absolute value (magnitude) of a complex number (modulus) https://en.wikipedia.org/wiki/Complex_number#Absolute_value_and_argument. More...
 
 arg ()
 The argument (phase) of a complex number The argument of z is the angle of the radius OP with the positive real axis, and is written as arg(z). More...
 
 sqrt ()
 The square root of a complex number https://en.wikipedia.org/wiki/Complex_number#Square_root. More...
 
 roots ()
 The roots of a complex number https://en.wikipedia.org/wiki/Complex_number#Square_root. More...
 
 inverse ()
 The inverse of a complex number (reciprocal) More...
 
 negate ()
 Negate the complex number Switches the signs of both the real and imaginary parts. More...
 
 polarForm ()
 Polar form https://en.wikipedia.org/wiki/Complex_number#Polar_form. More...
 
 add ($c)
 Complex addition https://en.wikipedia.org/wiki/Complex_number#Addition_and_subtraction. More...
 
 subtract ($c)
 Complex subtraction https://en.wikipedia.org/wiki/Complex_number#Addition_and_subtraction. More...
 
 multiply ($c)
 Complex multiplication https://en.wikipedia.org/wiki/Complex_number#Multiplication_and_division. More...
 
 divide ($c)
 Complex division Dividing two complex numbers is accomplished by multiplying the first by the inverse of the second https://en.wikipedia.org/wiki/Complex_number#Multiplication_and_division. More...
 
 equals (Complex $c)
 Test for equality Two complex numbers are equal if and only if both their real and imaginary parts are equal. More...
 

Public Attributes

const EPSILON = 1e-6
 Floating-point range near zero to consider insignificant.
 

Protected Attributes

 $r
 
 $i
 

Detailed Description

Class: Complex Complex Numbers.

A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers and i is the imaginary unit, satisfying the equation i² = −1. In this expression, a is the real part and b is the imaginary part of the complex number. https://en.wikipedia.org/wiki/Complex_number

Constructor & Destructor Documentation

◆ __construct()

MathPHP\Number\Complex::__construct (   $r,
  $i 
)

Constructor: __construct.

Parameters
number$rReal part
number$iImaginary part

Member Function Documentation

◆ __get()

MathPHP\Number\Complex::__get ( string  $part)

Function: __get Get r or i.

Parameters
string$part
Returns
number
Exceptions
Exception

◆ __toString()

MathPHP\Number\Complex::__toString ( )

Function: __toString String representation of a complex number a + bi, a - bi, etc.

Returns
string

◆ abs()

MathPHP\Number\Complex::abs ( )

The absolute value (magnitude) of a complex number (modulus) https://en.wikipedia.org/wiki/Complex_number#Absolute_value_and_argument.

If z = a + bi


|z| = √a² + b²

Returns
number

◆ add()

MathPHP\Number\Complex::add (   $c)

Complex addition https://en.wikipedia.org/wiki/Complex_number#Addition_and_subtraction.

(a + bi) + (c + di) = (a + c) + (b + d)i

Parameters
mixed$c
Returns
Complex
Exceptions
Exception

Implements MathPHP\Number\ObjectArithmetic.

◆ arg()

MathPHP\Number\Complex::arg ( )

The argument (phase) of a complex number The argument of z is the angle of the radius OP with the positive real axis, and is written as arg(z).

https://en.wikipedia.org/wiki/Complex_number#Absolute_value_and_argument

If z = a + bi arg(z) = atan(b, a)

Returns
number

◆ complexConjugate()

MathPHP\Number\Complex::complexConjugate ( )

The conjugate of a complex number.

https://en.wikipedia.org/wiki/Complex_number#Conjugate

Returns
Complex

◆ divide()

MathPHP\Number\Complex::divide (   $c)

Complex division Dividing two complex numbers is accomplished by multiplying the first by the inverse of the second https://en.wikipedia.org/wiki/Complex_number#Multiplication_and_division.

Parameters
mixed$c
Returns
Complex
Exceptions
Exception

◆ equals()

MathPHP\Number\Complex::equals ( Complex  $c)

Test for equality Two complex numbers are equal if and only if both their real and imaginary parts are equal.

https://en.wikipedia.org/wiki/Complex_number#Equality

Parameters
Complex$c
Returns
bool

◆ inverse()

MathPHP\Number\Complex::inverse ( )

The inverse of a complex number (reciprocal)

https://en.wikipedia.org/wiki/Complex_number#Reciprocal

Returns
Complex
Exceptions
Exception

◆ multiply()

MathPHP\Number\Complex::multiply (   $c)

Complex multiplication https://en.wikipedia.org/wiki/Complex_number#Multiplication_and_division.

(a + bi)(c + di) = (ac - bd) + (bc + ad)i

Parameters
mixed$c
Returns
Complex
Exceptions
Exception

Implements MathPHP\Number\ObjectArithmetic.

◆ negate()

MathPHP\Number\Complex::negate ( )

Negate the complex number Switches the signs of both the real and imaginary parts.

Returns
Complex

◆ polarForm()

MathPHP\Number\Complex::polarForm ( )

Polar form https://en.wikipedia.org/wiki/Complex_number#Polar_form.

z = a + bi = r(cos(θ) + i sin(θ)) Where r = |z| θ = arg(z) (in radians)

Returns
Complex

◆ roots()

MathPHP\Number\Complex::roots ( )

The roots of a complex number https://en.wikipedia.org/wiki/Complex_number#Square_root.

The roots of a + bi (with b ≠ 0) are ±(γ + δi), where

    ____________
   /     _______
  / a + √a² + b²

γ = / ---------— √ 2

      ____________
     /      _______
    / -a + √a² + b²

δ = sgn(b) / ----------— √ 2

Returns
array Complex[] (two roots)

◆ sqrt()

MathPHP\Number\Complex::sqrt ( )

The square root of a complex number https://en.wikipedia.org/wiki/Complex_number#Square_root.

The roots of a + bi (with b ≠ 0) are ±(γ + δi), where

    ____________
   /     _______
  / a + √a² + b²

γ = / ---------— √ 2

      ____________
     /      _______
    / -a + √a² + b²

δ = sgn(b) / ----------— √ 2

The square root returns the positive root.

Returns
Complex (positive root)

◆ subtract()

MathPHP\Number\Complex::subtract (   $c)

Complex subtraction https://en.wikipedia.org/wiki/Complex_number#Addition_and_subtraction.

(a + bi) - (c + di) = (a - c) + (b - d)i

Parameters
mixed$c
Returns
Complex
Exceptions
Exception

Implements MathPHP\Number\ObjectArithmetic.


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