MathComplexNumbersThis is a Pine Script library for handling complex numbers without arrays. It contains several utility functions for performing various operations on complex numbers, including converting complex numbers into tuples, getting the real and imaginary parts of a complex number, adding and subtracting complex numbers, computing the conjugate, multiplying and dividing complex numbers, computing the reciprocal, the inverse, the negative, the exponential, the ceil and the radius of a complex number.
The library exports a complex data type which consists of two float values: re, the real part of the complex number, and im, the imaginary part of the complex number.
The complex_tuple function and ct function convert a complex number into a tuple, and the get_real, get_imaginary, re, and im functions return the real and imaginary parts of a complex number.
The add and subtract functions add and subtract two complex numbers, respectively, by performing the appropriate arithmetic operations on their real and imaginary parts. The conjugate function returns the complex conjugate of a given complex number, which is the same as the original number but with the sign of its imaginary part reversed. The multiply and divide functions multiply and divide two complex numbers, respectively, according to the rules of complex arithmetic. The reciprocal function computes the reciprocal or inverse of a given complex number, while the inverse function computes the inverse of a given complex number. The negative function returns the negative of a given complex number, and the exponential function computes the exponential of a given complex number. The ceil function rounds a given complex number up to a specified number of digits. The radius function computes the radius (magnitude) of a given complex number, which is defined as its distance from the origin (0,0) of the complex plane.
Complex
MathSpecialFunctionsDiscreteFourierTransformLibrary "MathSpecialFunctionsDiscreteFourierTransform"
Method for Complex Discrete Fourier Transform (DFT).
dft(inputs, inverse) Complex Discrete Fourier Transform (DFT).
Parameters:
inputs : float array, pseudo complex array of paired values .
inverse : bool, invert the transformation.
Returns: float array, pseudo complex array of paired values .
MathComplexEvaluateLibrary "MathComplexEvaluate"
TODO: add library description here
is_op(char) Check if char is a operator.
Parameters:
char : string, 1 character string.
Returns: bool.
operator(op, left, right) operation between left and right values.
Parameters:
op : string, operator string character.
left : float, left value of operation.
right : float, right value of operation.
operator_precedence(op) level of precedence of operator.
Parameters:
op : string, operator 1 char string.
Returns: int.
eval() evaluate a string with references to a array of arguments.
| @param tokens string, arithmetic operations with references to indices in arguments, ex:"0+1*0+2*2+3" arguments
| @param arguments float array, arguments.
| @returns float, solution.
MathComplexTrignometryLibrary "MathComplexTrignometry"
Methods for complex number trignometry operations.
sinh(complex) Hyperbolic Sine of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
cosh(complex) Hyperbolic cosine of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
tanh(complex) Hyperbolic tangent of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
coth(complex) Hyperbolic cotangent of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
sech(complex) Hyperbolic Secant of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
csch(complex) Hyperbolic Cosecant of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
sin(complex) Trigonometric Sine of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
cos(complex) Trigonometric cosine of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
tan(complex) Trigonometric tangent of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
cot(complex) Trigonometric cotangent of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
sec(complex) Trigonometric Secant of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
csc(complex) Trigonometric Cosecant of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
asin(complex) Trigonometric Arc Sine of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
acos(complex) Trigonometric Arc Cosine of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
atan(complex) Trigonometric Arc Tangent of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
acot(complex) Trigonometric Arc Cotangent of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
asec(complex) Trigonometric Arc Secant of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
acsc(complex) Trigonometric Arc Cosecant of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
asinh(complex) Hyperbolic Arc Sine of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
acosh(complex) Hyperbolic Arc Cosine of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
atanh(complex) Hyperbolic Arc Tangent of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
acoth(complex) Hyperbolic Arc Cotangent of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
asech(complex) Hyperbolic Arc Secant of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
acsch(complex) Hyperbolic Arc Cosecant of complex number.
Parameters:
complex : float array, complex number.
Returns: float array.
MathComplexExtensionLibrary "MathComplexExtension"
A set of utility functions to handle complex numbers.
get_phase(complex_number, in_radians) The phase value of complex number complex_number.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
in_radians : boolean, value for the type of angle value, default=true, options=(true: radians, false: degrees)
Returns: float value with phase.
natural_logarithm(complex_number) Natural logarithm of complex number (base E).
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, complex number.
common_logarithm(complex_number) Common logarithm of complex number (base 10).
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, complex number.
logarithm(complex_number, base) Common logarithm of complex number (custom base).
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
base : float, base value.
Returns: float array, complex number.
power(complex_number, complex_exponent) Raise complex_number with complex_exponent.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
complex_exponent : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
root(complex_number, complex_exponent) Raise complex_number with inverse of complex_exponent.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
complex_exponent : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
square(complex_number) Square of complex_number (power 2).
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
square_root(complex_number) Square root of complex_number (power 1/2).
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
square_roots(complex_number) Square root of complex_number (power 1/2).
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: tuple with 2 complex numbers.
cubic_roots(complex_number) Square root of complex_number (power 1/2).
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: tuple with 2 complex numbers.
to_polar_form(complex_number, in_radians) The polar form value of complex_number.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
in_radians : boolean, value for the type of angle value, default=true, options=(true: radians, false: degrees)
Returns: float array, pseudo complex number in the form of a array
** returns a array
MathComplexOperatorLibrary "MathComplexOperator"
A set of utility functions to handle complex numbers.
conjugate(complex_number) Computes the conjugate of complex_number by reversing the sign of the imaginary part.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
add(complex_number_a, complex_number_b) Adds complex number complex_number_b to complex_number_a, in the form:
.
Parameters:
complex_number_a : pseudo complex number in the form of a array .
complex_number_b : pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
subtract(complex_number_a, complex_number_b) Subtract complex_number_b from complex_number_a, in the form:
.
Parameters:
complex_number_a : float array, pseudo complex number in the form of a array .
complex_number_b : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
multiply(complex_number_a, complex_number_b) Multiply complex_number_a with complex_number_b, in the form:
Parameters:
complex_number_a : float array, pseudo complex number in the form of a array .
complex_number_b : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
divide(complex_number_a, complex_number_b) Divide complex_number _a with _b, in the form:
Parameters:
complex_number_a : float array, pseudo complex number in the form of a array .
complex_number_b : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
reciprocal(complex_number) Computes the reciprocal or inverse of complex_number.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
negative(complex_number) Negative of complex_number, in the form:
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
inverse(complex_number) Inverse of complex_number, in the form:
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
exponential(complex_number) Exponential of complex_number.
Parameters:
complex_number : pseudo complex number in the form of a array .
Returns: float array, pseudo complex number in the form of a array
ceil(complex_number, digits) Ceils complex_number.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
digits : int, digits to use as ceiling.
Returns: _complex: pseudo complex number in the form of a array
radius(complex_number) Radius(magnitude) of complex_number, in the form:
This is defined as its distance from the origin (0,0) of the complex plane.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float value with radius.
magnitude(complex_number) magnitude(absolute value) of complex_number, should be the same as the radius.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float.
magnitude_squared(complex_number) magnitude(absolute value) of complex_number, should be the same as the radius.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float.
sign(complex_number) Unity of complex numbers.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
Returns: float array, complex number.
MathComplexArrayLibrary "MathComplexArray"
Array methods to handle complex number arrays.
new(size, initial_complex) Prototype to initialize a array of complex numbers.
Parameters:
size : size of the array.
initial_complex : Complex number to be used as default value, in the form of array .
Returns: float array, pseudo complex Array in the form of a array
get(id, index) Get the complex number in a array, in the form of a array
Parameters:
id : float array, ID of the array.
index : int, Index of the complex number.
Returns: float array, pseudo complex number in the form of a array
set(id, index, complex_number) Sets the values complex number in a array.
Parameters:
id : float array, ID of the array.
index : int, Index of the complex number.
complex_number : float array, Complex number, in the form: .
Returns: Void, updates array id.
push(id, complex_number) Push the values into a complex number array.
Parameters:
id : float array, ID of the array.
complex_number : float array, Complex number, in the form: .
Returns: Void, updates array id.
pop(id, complex_number) Pop the values from a complex number array.
Parameters:
id : float array, ID of the array.
complex_number : float array, Complex number, in the form: .
Returns: Void, updates array id.
to_string(id, format) Reads a array of complex numbers into a string, of the form: " [ , ... ]""
Parameters:
id : float array, ID of the array.
format : string, format of the number conversion, default='#.##########'.
Returns: string, translated complex array into string.
MathComplexCoreLibrary "MathComplexCore"
Core functions to handle complex numbers.
set_real(complex_number, real) Set the real part of complex_number.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
real : float, value to replace real value of complex_number.
Returns: Void, Modifies complex_number.
set_imaginary(complex_number, imaginary) Set the imaginary part of complex_number.
Parameters:
complex_number : float array, pseudo complex number in the form of a array .
imaginary : float, value to replace imaginary value of complex_number.
Returns: Void, Modifies complex_number.
new(real, imaginary) Creates a prototype array to handle complex numbers.
Parameters:
real : float, real value of the complex number. default=0.
imaginary : float, imaginary number of the complex number. default=0.
@return float array, pseudo complex number in the form of a array .
zero() complex number "0+0i".
@return float array, pseudo complex number in the form of a array .
one() complex number "1+0i".
@return float array, pseudo complex number in the form of a array .
imaginary_one() complex number "0+1i".
@return float array, pseudo complex number in the form of a array .
nan() complex number "0+1i".
@return float array, pseudo complex number in the form of a array .
from_polar_coordinates(magnitude, phase) Create a complex number from a point's polar coordinates.
Parameters:
magnitude : float, default=0.0, The magnitude, which is the distance from the origin (the intersection of the x-axis and the y-axis) to the number.
phase : float, default=0.0, The phase, which is the angle from the line to the horizontal axis, measured in radians.
@return float array, pseudo complex number in the form of a array .
get_real(complex_number) Get the real part of complex_number.
Parameters:
complex_number : pseudo complex number in the form of a array .
Returns: float, Real part of the complex_number.
get_imaginary(complex_number) Get the imaginary part of complex_number.
Parameters:
complex_number : pseudo complex number in the form of a array .
Returns: float, Imaginary part of the complex number.
is_complex(complex_number) Checks that its a valid complex_number.
Parameters:
complex_number : pseudo complex number in the form of a array .
Returns: bool.
is_nan(complex_number) Checks that its empty "na" complex_number.
Parameters:
complex_number : pseudo complex number in the form of a array .
Returns: bool.
is_real(complex_number) Checks that the complex_number is real.
Parameters:
complex_number : pseudo complex number in the form of a array .
Returns: bool.
is_real_non_negative(complex_number) Checks that the complex_number is real and not negative.
Parameters:
complex_number : pseudo complex number in the form of a array .
Returns: bool.
is_zero(complex_number) Checks that the complex_number is zero.
Parameters:
complex_number : pseudo complex number in the form of a array .
Returns: bool.
equals(complex_number_a, complex_number_b) Compares two complex numbers:
Parameters:
complex_number_a : float array, pseudo complex number in the form of a array .
complex_number_b : float array, pseudo complex number in the form of a array .
Returns: boolean value representing the equality.
to_string(complex, format) Converts complex_number to a string format, in the form: "a+bi"
Parameters:
complex : pseudo complex number in the form of a array .
format : string, formating to apply.
Returns: a string in "a+bi" format