Scol standard library package  0.3.1
Common and usefull functions for all Scol applications
Classes | Functions
The Scol complex numbers standard API.

Classes

struct  Complex
 Internal structure. You should not call it directly, use API instead ! More...
 

Functions

 std_cAdd (c1, c2)
 Add two complex numbers. More...
 
 std_cAddNew (c1, c2)
 Add two complex numbers. The return is a new complex number. More...
 
 std_cArg (c, flag)
 Get the argument of a complex number. More...
 
 std_cCmp (c1, c2)
 Compare two complex numbers. More...
 
 std_cConjugate (c)
 Create the conjugate of a complex number. More...
 
 std_cDiv (c1, c2)
 Divide two complex numbers. More...
 
 std_cDivNew (c1, c2)
 Divide two complex numbers. The return is a new complex number. More...
 
 std_cEuler (f)
 Exponentiation by the Euler's formula : \(e^{f*i}\) where i is the imaginary unit ( \(i² = -1\)) and f is a real number (here, f is a floatting point number). More...
 
 std_cFromS (szC)
 Create a new Complex from a literal string (such as \(a + bi\)) More...
 
 std_cGet (c)
 Get a complex number. More...
 
 std_cGetImg (c)
 Get the imaginary part of a complex number. More...
 
 std_cGetReal (c)
 Get the real part of a complex number. More...
 
 std_cInv (c)
 Returns the inverse of a complex number. More...
 
 std_cInvNew (c)
 Returns the inverse of a complex number. This is a new complex number. More...
 
 std_cIsZero (c)
 Check if a complex number is 0. More...
 
 std_cLog (c)
 The natural logarithm (base 'e') of a complex number. More...
 
 std_cLogNew (c)
 Returns the first solution of the natural logarithm (base 'e') of a complex number. The return is a new complex number. More...
 
 std_cMod (c)
 Get the modulus (phasis) of a complex number. More...
 
 std_cMul (c1, c2)
 Multiply two complex numbers. More...
 
 std_cMulNew (c1, c2)
 Multiply two complex numbers. The return is a new complex number. More...
 
 std_cNew (fReal, fImg)
 Create a new Complex. More...
 
 std_cPow (c, i)
 The power of a complex number by an integer. More...
 
 std_cPowNew (c, i)
 The power of a complex number by an integer The return is a new complex number. More...
 
 std_cRootn (c, i)
 Returns the first solution of the n-th root of a complex number. More...
 
 std_cRootnAll (c, i)
 Returns all n-th roots of a complex number. More...
 
 std_cRootnK (c, i, k)
 Returns a particular soultion of the n-th root of a complex number. More...
 
 std_cRootnNew (c, i)
 Returns the first solution of the n-th root of a complex number. The return is a new complex number. More...
 
 std_cSet (c, fReal, fImg)
 Set a complex number. More...
 
 std_cSetImg (c, fImg)
 Set the imaginary part of a complex number. More...
 
 std_cSetReal (c, fReal)
 Set the real part of a complex number. More...
 
 std_cSqr (c)
 The square of a complex number. More...
 
 std_cSqrNew (c)
 Square of a complex number. The return is a new complex number. More...
 
 std_cSqrt (c)
 Square root of a complex number. More...
 
 std_cSqrtNew (c)
 Square root of a complex number. The return is two new complex numbers. More...
 
 std_cSub (c1, c2)
 Substract two complex numbers. More...
 
 std_cSubNew (c1, c2)
 Substract two complex numbers. The return is a new complex number. More...
 
 std_cToS (c)
 Get a complex number to a literal string (like \(a+bi\)) More...
 
 std_cZero ()
 Create a new zero (0) Complex : \(0+0i\). More...
 

Detailed Description

Package to load : lib/std/complex.pkg

Dependancies :

Function Documentation

std_cNew ( fReal  ,
fImg   
)

Create a new Complex.

Prototype: fun [F F] Complex

Parameters
F: the real part
F: the imaginary part
Returns
Complex : the new complex number
std_cFromS ( szC  )

Create a new Complex from a literal string (such as \(a + bi\))

Prototype: fun [S] Complex

Parameters
S: a literal complex string.
Returns
Complex : the new complex number
std_cZero ( )

Create a new zero (0) Complex : \(0+0i\).

Prototype: fun [] Complex

Returns
Complex : the new complex number
std_cIsZero ( )

Check if a complex number is 0.

Prototype: fun [Complex] I

Returns
I : 1 if 0
std_cSetReal ( ,
fReal   
)

Set the real part of a complex number.

Prototype: fun [Complex F] Complex

Parameters
Complex: a complex number.
F: the new real part.
Returns
Complex : the same complex number structure
std_cSetImg ( ,
fImg   
)

Set the imaginary part of a complex number.

Prototype: fun [Complex F] Complex

Parameters
Complex: a complex number.
F: the new imaginary part.
Returns
Complex : the same complex number structure
std_cSet ( ,
fReal  ,
fImg   
)

Set a complex number.

Prototype: fun [Complex F F] Complex

Parameters
Complex: a complex number.
F: the new real part.
F: the new imaginary part.
Returns
Complex : the same complex number structure
std_cGetReal ( )

Get the real part of a complex number.

Prototype: fun [Complex] F

Parameters
Complex: a complex number.
Returns
F : the real part
std_cGetImg ( )

Get the imaginary part of a complex number.

Prototype: fun [Complex] F

Parameters
Complex: a complex number.
Returns
F : the imaginary part
std_cGet ( )

Get a complex number.

Prototype: fun [Complex] [F F]

Parameters
Complex: a complex number.
Returns
[F F] : the real part and the imaginary part
std_cToS ( )

Get a complex number to a literal string (like \(a+bi\))

Prototype: fun [Complex] S

Parameters
Complex: a complex number.
Returns
S : the literal string
std_cConjugate ( )

Create the conjugate of a complex number.

The conjugate of \(a+bi\) is \(a-bi\).

Prototype: fun [Complex] Complex

Parameters
Complex: a complex number.
Returns
Complex : its conjugate (a new Complex number)
std_cMod ( )

Get the modulus (phasis) of a complex number.

The modulus of \(a+bi\) is \(|a-bi| = \sqrt{(a²+b²)}\)

Prototype: fun [Complex] F

Parameters
Complex: a complex number.
Returns
F : its modulus
std_cArg ( ,
flag   
)

Get the argument of a complex number.

The argument (or phasis) of \(a+bi\) is \(\arctan {b / a}\).

Prototype: fun [Complex I] F

Parameters
Complex: a complex number.
I: a flag. In the case where a and b are equals at 0 (zero), this function returns 0 if this flag is 0 or nil if this flag has another value. Indeed, in mathematics, this value is undefined but the many language, like C, returns 0 instead of a 'NaN' (Not a Number).
Returns
F : its argument, in radians (see above)
std_cAdd ( c1  ,
c2   
)

Add two complex numbers.

Prototype: fun [Complex Complex] [F F]

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
[F F] : the result (real part and imaginary part)
See also
std_cAddNew
std_cAddNew ( c1  ,
c2   
)

Add two complex numbers. The return is a new complex number.

Prototype: fun [Complex Complex] Complex

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
Complex : a new Complex number
See also
std_cAdd
std_cSub ( c1  ,
c2   
)

Substract two complex numbers.

Prototype: fun [Complex Complex] [F F]

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
[F F] : the result (real part and imaginary part)
See also
std_cSubNew
std_cSubNew ( c1  ,
c2   
)

Substract two complex numbers. The return is a new complex number.

Prototype: fun [Complex Complex] Complex

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
Complex : a new Complex number
See also
std_cSub
std_cMul ( c1  ,
c2   
)

Multiply two complex numbers.

Prototype: fun [Complex Complex] [F F]

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
[F F] : the result (real part and imaginary part)
See also
std_cMulNew
std_cMulNew ( c1  ,
c2   
)

Multiply two complex numbers. The return is a new complex number.

Prototype: fun [Complex Complex] Complex

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
Complex : a new Complex number
See also
std_cMul
std_cDiv ( c1  ,
c2   
)

Divide two complex numbers.

Prototype: fun [Complex Complex] [F F]

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
[F F] : the result (real part and imaginary part)
See also
std_cDivNew
std_cDivNew ( c1  ,
c2   
)

Divide two complex numbers. The return is a new complex number.

Prototype: fun [Complex Complex] Complex

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
Complex : a new Complex number
See also
std_cDiv
std_cInv ( )

Returns the inverse of a complex number.

Prototype: fun [Complex] [F F]

Parameters
Complex: a complex number.
Returns
[F F] : the result (real part and imaginary part), nil if error
See also
std_cInvNew
std_cPow (n = -1)
std_cInvNew ( )

Returns the inverse of a complex number. This is a new complex number.

Prototype: fun [Complex] Complex

Parameters
Complex: a complex number.
Returns
Complex : a new Complex number or nil if error
See also
std_cInv
std_cPowNew (n = -1)
std_cSqr ( )

The square of a complex number.

Prototype: fun [Complex] [F F]

Parameters
Complex: a complex number.
Returns
[F F] : the result (real part and imaginary part)
See also
std_cSqrNew
std_cSqrNew ( )

Square of a complex number. The return is a new complex number.

Prototype: fun [Complex] Complex

Parameters
Complex: a complex number.
Returns
Complex : a new Complex number
See also
std_cSqr
std_cSqrt ( )

Square root of a complex number.

Prototype: fun [Complex] [[F F] [F F]]

Parameters
Complex: a complex number.
Returns
[[F F] [F F]] : the result (two complex numbers with their real part and imaginary part)
See also
std_cSqrtNew
std_cSqrtNew ( )

Square root of a complex number. The return is two new complex numbers.

Prototype: fun [Complex] [Complex Complex]

Parameters
Complex: a complex number.
Returns
[Complex Complex] : two new Complex number
See also
std_cSqrt
std_cPow ( ,
 
)

The power of a complex number by an integer.

Prototype: fun [Complex I] [F F]

Parameters
Complex: a complex number.
I: an integer
Returns
[F F] : the result (real part and imaginary part)
See also
std_cPowNew
std_cPowNew ( ,
 
)

The power of a complex number by an integer The return is a new complex number.

Prototype: fun [Complex I] Complex

Parameters
Complex: a complex number.
I: an integer
Returns
Complex : a new Complex number
See also
std_cPow
std_cRootn ( ,
 
)

Returns the first solution of the n-th root of a complex number.

Prototype: fun [Complex I] [F F]

Parameters
Complex: a complex number.
I: an integer
Returns
[F F] : the simplier result (real part and imaginary part)
Remarks
In fact, the n-th root of a complex number is 'multi valued'.
See also
std_cRootnNew
std_cRootnK for a particular value
std_cRootnAll for all values
std_cRootnNew ( ,
 
)

Returns the first solution of the n-th root of a complex number. The return is a new complex number.

Prototype: fun [Complex I] Complex

Parameters
Complex: a complex number.
I: an integer
Returns
Complex : a new Complex number (only the first value is returned here).
See also
std_cRootn
std_cRootnK
std_cRootnAll
std_cRootnAll ( ,
 
)

Returns all n-th roots of a complex number.

The part real is :

(the n-th root of modulus) * cosine ((the argument + 2*k*Pi) / n)

\(\sqrt[n]{(a²+b²)} * \cos {((\arctan {b / a} + 2*k*\Pi)/n)}\)

The imaginary part is :

(the n-th root of modulus) * sine ((the argument + 2*k*Pi) / n)

\(\sqrt[n]{(a²+b²)} * \sin {((\arctan {b / a} + 2*k*\Pi)/n)}\)

where 'k' is an integer, with \(0 <= k < n\).

Prototype: fun [Complex I] [[I F F] r1]

Parameters
Complex: a complex number.
I: an integer (the 'n_th')
Returns
[[I F F] r1] : a list of all values. The first item of each tuple is the indice 'k'. The size of the list is 'n'.
See also
std_cRootn for 'k' = 0
std_cRootnNew for 'k' = 0
std_cRootnK for a given 'k'
std_cRootnK ( ,
,
 
)

Returns a particular soultion of the n-th root of a complex number.

Prototype: fun [Complex I I] [F F]

Parameters
Complex: a complex number.
I: an integer, the 'n'-th root
I: k : a particular solution (see std_cRootnAll for more details) k must be positive or nul and strictly lower than n (else, nil is returned)
Returns
[F F] : the result (real part and imaginary part)
See also
std_cRootnNew for 'k' = 0
std_cRootn for 'k' = 0
std_cRootnAll for all 'k'
std_cLog ( )

The natural logarithm (base 'e') of a complex number.

Prototype: fun [Complex] [F F]

Parameters
Complex: a complex number.
Returns
[F F] : the result (real part and imaginary part)
Remarks
Cosine and sine being periodic functions, the natural logarithm of a complex number is also periodic. So, only the simple value is returned here, i.E. when 'k' = 0. To obtain all values, it need to apply this formula :

the real part is : log of modulus : \(\ln {\sqrt{(a²+b²)}}\)

the imaginary part is : the argument + 2*k*Pi : \(\arctan {b / a}+ 2*k*\Pi\)

where 'k' is an integer (in \(\mathbb{Z}\))

If you want a particular result, add \(2k\Pi\) to the returned imaginary part.

std_cLogNew ( )

Returns the first solution of the natural logarithm (base 'e') of a complex number. The return is a new complex number.

Prototype: fun [Complex] Complex

Parameters
Complex: a complex number.
Returns
Complex : a new Complex number (only the first value is returned here).
See also
std_cLog for 'k' = 0 (see std_cLog for more details)
std_cEuler ( )

Exponentiation by the Euler's formula : \(e^{f*i}\) where i is the imaginary unit ( \(i² = -1\)) and f is a real number (here, f is a floatting point number).

e power fi = cos f + i sin f

\(e^{f*i} = \cos {f} + i*\sin{f}\)

Prototype: fun [F] [F F]

Parameters
F: a floating point number.
Returns
[F F] : the result (real part and imaginary part)
std_cCmp ( c1  ,
c2   
)

Compare two complex numbers.

Prototype: fun [Complex Complex] I

Parameters
Complex: a complex number.
Complex: a second complex number.
Returns
Complex : 1 if equals
Remarks
It is not possible to define an order between two complex number. So, only the equality can be defined and here 1 is returned in this case.