Project

General

Profile

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

Detailed Description

Package to load : lib/std/complex.pkg

Dependancies :

  • none

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).

<b>Prototype:</b> 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| = (a²+b²)^(1/2)

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 arctangent of b and 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)

The imaginary part is :

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

where 'k' is an integer, with k <= 0 < 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 the imaginary part is : the argument + 2*k*Pi

where 'k' is an integer (in Z set)

If you want a particular result, add '2kPi' 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 power fi 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

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.