Programming Reference for VirtualLab Fusion  2025.1
Loading...
Searching...
No Matches
MathFunctions Class Reference

This class contains various mathematical functions and constants. More...

Static Public Member Functions

static double Abs (this double number)
 Returns the absolute value of the double number.
 
static double Cos (double d)
 Special cosine function as the Math.Cos function has problems with with large values (in .Net Framework 4.8) and with \(\cos\left(\frac{\pi}{2}\right)\) in general.
 
static double DegreeToRadian (double degree)
 Convert Degree to Radian.
 
static List< int[]> DrawAllSubsetsOfGivenSizeFromSetOfIndices (int subsetSize, int populationSize)
 Method for creating all possible subsets of a given size out of a set of indices.
 
static double Factorial (int m)
 Calculates the factorial \(n!\).
 
static int GetQuantizationLevel (double value, double minimumQuantizedValue, double maximumQuantizedValue, double quantizationDifference)
 Gets the quantization level on which a certain value lies.
 
static double GetQuantizedValue (double value, double minimumQuantizedValue, double maximumQuantizedValue, double quantizationDifference)
 Gets the quantized value.
 
static double IndexOfTriangleNumber (int number)
 The ith triangle number is i * (i+1) / 2 which we have solved for i to return the double index of the matching triangle number. For example this method returns 2.0 for 3 because 3 is the second triangle number. It returns 2.4 for 4 which means that 4 is above the second and below the third triangle number.
 
static void InitQuantizationMinMaxRiser (double minimum, double maximum, int numberOfQuantizationLevels, out double minimumQuantizedValue, out double maximumQuantizedValue, out double quantizationDifference)
 Initializes a "Min-Max-Riser" quantization.
 
static void InitQuantizationMinMaxTread (double minimum, double maximum, int numberOfQuantizationLevels, out double minimumQuantizedValue, out double maximumQuantizedValue, out double quantizationDifference)
 Initializes a "Min-Max-Tread" quantization.
 
static double NumericDerivative (Func< double, double > function, double position, double epsilon=Globals.Epsilon)
 Calculates the numerical derivative of a function.
 
static double Pow (double baseNumber, double exponent)
 Raises the double number to the given power.
 
static Complex QuantizePoint (Complex point, int amplitudeLevels, int phaseLevels)
 Quantizes a value in the amplitude range \(0 \ldots 1\) and the phase range \(-\pi \ldots \pi\). The phase levels are calculated with the following formula: \(\frac{\pi}{2} - k \cdot \frac{\pi}{n}\). \(n\) is the number of phase levels, \(k = 0, \ldots, n-1\).
 
static Complex QuantizePoint (Complex point, int amplitudeLevels, int phaseLevels, double factor)
 Quantizes a value in the amplitude range \(0 \ldots 1\) and the phase range \(-\pi \ldots \pi\). The phase levels are calculated with the following formula: \(\frac{\pi}{2} - k \cdot \frac{\pi}{n}\). \(n\) is the number of phase levels, \(k = 0, \ldots, n-1\).
 
static double RadianToDegree (double radian)
 Convert Degree to Radian.
 
static double RMS (LargeList< double > values, bool relativeToAverage=false, LargeList< double > weights=null)
 Calculates the RMS (root mean square) of the given value.
 
static double RMS (LargeList< double > values, double average)
 Calculates the RMS (root mean square) of the given value with respect to the given average.
 
static double RombergIntegral (RealFunctionWithSingleArgument f, double xmin, double xmax, int n)
 Computes the definite integral of the real function \(f\) in the range from xmin to xmax. Romberg integration with \(2^{(n-1)+1}\) equidistant function evaluations is used to this end.
 
static double Sin (double d)
 Special sine function as the Math.Sin function has problems with large values (in .Net Framework 4.8) and with \(\sin\left(\pi\right)\) in general.

 
static int SolveQuadraticEquation (double a2, double a1, double a0, out double x1, out double x2)
 Function solving the general quadratic equation \(0 = a_2 \cdot x^2 + a_1 \cdot x + a_0\) .
 
static double SphericalPhase (VectorD position, double k, double radius, double signumZ, double signumKz)
 Calculates the phase of the spherical phase function on the position \(\boldsymbol{r}\). The spherical phase function is defined as \(f(\boldsymbol{r}) = \exp{(\text{signumZ} \cdot \text{signumKz} \cdot k \cdot a)}\) with \(a = \sqrt{(x^2 + y^2 + z^2)}\).
 
static VectorD SphericalPhaseDerivative (VectorD position, double k, double radius, double signumZ, double signumKz)
 Calculates the first derivative of spherical phase function (not a complex number but just the phase value). The spherical phase function is defined as \(f(\boldsymbol{r}) = \exp{(signumZ * signumKz * k * a)}\) with \(a = \sqrt{(x^2 + y^2 + z^2)}\).
 
static Complex SphericalPhaseFunction (VectorD position, double k, double radius, double signumZ, double signumKz)
 Calculates the value of a spherical phase function on the position \(\boldsymbol{r}\). The spherical phase function is defined as \(f(\boldsymbol{r}) = \exp{(\text{signumZ} \cdot \text{signumKz} \cdot k \cdot a)}\) with \(a = \sqrt{(x^2 + y^2 + z^2)}\).
 
static void SymDefSolve (double[,] matr, ref double[] vect)
 Solves the linear system matr * x = vect by using the Cholesky decomposition of matr.
 
static double Tan (double d)
 Special tangent function as the Math.Tan function has problems with \(\tan\left(\frac{\pi}{2}\right)\) and \(\tan\left(\pi\right)\).
 
static double ToThePowerOf (this double baseNumber, double exponent)
 Raises the double number to the given power.
 
static int TriangleNumber (int index)
 Calculates the ith triangle number which is i * (i+1) / 2.
 

Static Public Attributes

const double HalfPi
 Constant value of \(\frac{\pi}{2}\).
 
const double TwoPi
 Constant value of \(2 \cdot \pi\).
 

Detailed Description

This class contains various mathematical functions and constants.

Member Function Documentation

◆ Abs()

static double Abs ( this double  number)
static

Returns the absolute value of the double number.

Parameters
numberThe double number.
Returns
The absolute value of the double number.

◆ Cos()

static double Cos ( double  d)
static

Special cosine function as the Math.Cos function has problems with with large values (in .Net Framework 4.8) and with \(\cos\left(\frac{\pi}{2}\right)\) in general.

Parameters
dThe argument of the cosine.
Returns
The cosine of d.

◆ DegreeToRadian()

static double DegreeToRadian ( double  degree)
static

Convert Degree to Radian.

Parameters
degreeThe angle in degree.
Returns
The angle in radian.

◆ DrawAllSubsetsOfGivenSizeFromSetOfIndices()

static List< int[]> DrawAllSubsetsOfGivenSizeFromSetOfIndices ( int  subsetSize,
int  populationSize 
)
static

Method for creating all possible subsets of a given size out of a set of indices.

Parameters
subsetSizeSize of the subses to draw.
populationSizeSize of the (zero based) index set. So the highest index is populationSize - 1.
Returns
List of all subsets of given size.

◆ Factorial()

static double Factorial ( int  m)
static

Calculates the factorial \(n!\).

Parameters
mOrder of factorial to calculate: \(n\).
Returns
\(n!\)

◆ GetQuantizationLevel()

static int GetQuantizationLevel ( double  value,
double  minimumQuantizedValue,
double  maximumQuantizedValue,
double  quantizationDifference 
)
static

Gets the quantization level on which a certain value lies.

Parameters
valueThe value to quantize.
minimumQuantizedValueThe value corresponding to the lowest quantization level.
maximumQuantizedValueThe value corresponding to the highest quantization level.
quantizationDifferenceThe difference between two consecutive quantization levels.
Returns
Index of the quantization level closest to the given value.

◆ GetQuantizedValue()

static double GetQuantizedValue ( double  value,
double  minimumQuantizedValue,
double  maximumQuantizedValue,
double  quantizationDifference 
)
static

Gets the quantized value.

Parameters
valueThe value to quantize.
minimumQuantizedValueThe value corresponding to the lowest quantization level.
maximumQuantizedValueThe value corresponding to the highest quantization level.
quantizationDifferenceThe difference between two consecutive quantization levels.
Returns
The quantized value.

◆ IndexOfTriangleNumber()

static double IndexOfTriangleNumber ( int  number)
static

The ith triangle number is i * (i+1) / 2 which we have solved for i to return the double index of the matching triangle number. For example this method returns 2.0 for 3 because 3 is the second triangle number. It returns 2.4 for 4 which means that 4 is above the second and below the third triangle number.

Parameters
numberThe number for which the index of the matching triangle number is determined.
Returns
The index of the matching triangle number. If you want to obtain the largest triangle number less than or equal the given number use a floor rounding on the result. If you want to obtain the smallest triangle number greater than or equal the given number use a ceiling rounding on the result.
Exceptions
System.ArgumentExceptionNumber must be larger or equal than zero.

◆ InitQuantizationMinMaxRiser()

static void InitQuantizationMinMaxRiser ( double  minimum,
double  maximum,
int  numberOfQuantizationLevels,
out double  minimumQuantizedValue,
out double  maximumQuantizedValue,
out double  quantizationDifference 
)
static

Initializes a "Min-Max-Riser" quantization.

Parameters
minimumThe minimum of the value range to quantize.
maximumThe maximum of the value range to quantize.
numberOfQuantizationLevelsThe number of quantization levels.
minimumQuantizedValueOut parameter to return the minimum quantized value.
maximumQuantizedValueOut parameter to return the maximum quantized value.
quantizationDifferenceOut parameter to return the difference between two consecutive quantization levels.

◆ InitQuantizationMinMaxTread()

static void InitQuantizationMinMaxTread ( double  minimum,
double  maximum,
int  numberOfQuantizationLevels,
out double  minimumQuantizedValue,
out double  maximumQuantizedValue,
out double  quantizationDifference 
)
static

Initializes a "Min-Max-Tread" quantization.

Parameters
minimumThe minimum of the value range to quantize.
maximumThe maximum of the value range to quantize.
numberOfQuantizationLevelsThe number of quantization levels.
minimumQuantizedValueOut parameter to return the minimum quantized value.
maximumQuantizedValueOut parameter to return the maximum quantized value.
quantizationDifferenceOut parameter to return the difference between two consecutive quantization levels.

◆ NumericDerivative()

static double NumericDerivative ( Func< double, double >  function,
double  position,
double  epsilon = Globals::Epsilon 
)
static

Calculates the numerical derivative of a function.

Parameters
functionThe function 𝑦 = f(𝑥).
positionThe position 𝑥 at which the derivative is calculated.
epsilonThe numerical derivative is calculated by calculating the function values at two positions 𝑥 + ε and 𝑥 - ε.
Returns
The numerical derivative of the function at the given position.

◆ Pow()

static double Pow ( double  baseNumber,
double  exponent 
)
static

Raises the double number to the given power.

Parameters
baseNumberThe base.
exponentThe exponent.
Returns
The double number to the power of the exponent.

◆ QuantizePoint() [1/2]

static Complex QuantizePoint ( Complex  point,
int  amplitudeLevels,
int  phaseLevels 
)
static

Quantizes a value in the amplitude range \(0 \ldots 1\) and the phase range \(-\pi \ldots \pi\). The phase levels are calculated with the following formula: \(\frac{\pi}{2} - k \cdot \frac{\pi}{n}\). \(n\) is the number of phase levels, \(k = 0, \ldots, n-1\).

Parameters
pointThe complex value to quantize.
amplitudeLevelsNumber of amplitude levels. Zero means no quantization.
phaseLevelsNumber of phase levels. Zero means no quantization.
Returns
The quantized complex value.

◆ QuantizePoint() [2/2]

static Complex QuantizePoint ( Complex  point,
int  amplitudeLevels,
int  phaseLevels,
double  factor 
)
static

Quantizes a value in the amplitude range \(0 \ldots 1\) and the phase range \(-\pi \ldots \pi\). The phase levels are calculated with the following formula: \(\frac{\pi}{2} - k \cdot \frac{\pi}{n}\). \(n\) is the number of phase levels, \(k = 0, \ldots, n-1\).

Parameters
pointThe complex value to quantize.
amplitudeLevelsNumber of amplitude levels. Zero means no quantization.
phaseLevelsNumber of phase levels. Zero means no quantization.
factorThe projection strength \(\lambda\). \(\lambda = 1\) means hard quantization and \(\lambda = 0\) means no quantization. Values of \(\lambda\) between 0 and 1 lead to soft quantization. The used formulas can be found in the quantization chapter of the manual.
Returns
The quantized complex value.

◆ RadianToDegree()

static double RadianToDegree ( double  radian)
static

Convert Degree to Radian.

Parameters
radianThe angle in radian.
Returns
The angle in degree.

◆ RMS() [1/2]

static double RMS ( LargeList< double >  values,
bool  relativeToAverage = false,
LargeList< double >  weights = null 
)
static

Calculates the RMS (root mean square) of the given value.

Parameters
valuesThe list of values.
relativeToAverageIf this optional parameter is set to true the RMS refers to the average value. Otherwise it refers to zero.
weightsOptional list containing a weight per value.
Returns
The RMS. NaN if zero values are given.
Exceptions
ArgumentExceptionRMS calculation: For every value there must be exactly one weight.

◆ RMS() [2/2]

static double RMS ( LargeList< double >  values,
double  average 
)
static

Calculates the RMS (root mean square) of the given value with respect to the given average.

Parameters
valuesThe list of values.
averageOptional average. Zero by default.
Returns
The RMS. NaN if zero values are given.

◆ RombergIntegral()

static double RombergIntegral ( RealFunctionWithSingleArgument  f,
double  xmin,
double  xmax,
int  n 
)
static

Computes the definite integral of the real function \(f\) in the range from xmin to xmax. Romberg integration with \(2^{(n-1)+1}\) equidistant function evaluations is used to this end.

Parameters
fDelegate of the real function \(f\) to integrate.
xminLower border of integration interval.
xmaxUpper border of integration interval.
nOrder of the method. 1 means trapezoidal, 2 means Simpson rule.
Returns
Approximate integral value.

◆ Sin()

static double Sin ( double  d)
static

Special sine function as the Math.Sin function has problems with large values (in .Net Framework 4.8) and with \(\sin\left(\pi\right)\) in general.

Parameters
dThe argument of the sine.
Returns
The sine of d.

◆ SolveQuadraticEquation()

static int SolveQuadraticEquation ( double  a2,
double  a1,
double  a0,
out double  x1,
out double  x2 
)
static

Function solving the general quadratic equation \(0 = a_2 \cdot x^2 + a_1 \cdot x + a_0\) .

Parameters
a2Coefficient of quadratic term.
a1Coefficient of linear term.
a0Coefficient of constant term.
x1Out parameter giving the solution if only one solution exists or the smaller of the two solutions.
x2Out parameter giving the larger solution in case of two solutions.
Returns
The number of solutions. Either -1, 0, 1, or 2. Two equal values in case of zero discriminant. -1 indicates that any x is a solution.

◆ SphericalPhase()

static double SphericalPhase ( VectorD  position,
double  k,
double  radius,
double  signumZ,
double  signumKz 
)
static

Calculates the phase of the spherical phase function on the position \(\boldsymbol{r}\). The spherical phase function is defined as \(f(\boldsymbol{r}) = \exp{(\text{signumZ} \cdot \text{signumKz} \cdot k \cdot a)}\) with \(a = \sqrt{(x^2 + y^2 + z^2)}\).

Parameters
positionPosition \(\boldsymbol{r}\) spherical phase is to be calculated for.
kAbsolute value of the wave vector \(k\).
radiusDistance \(z\) from the source plane of the spherical phase function.
signumZSign of the spherical phase radius, i.e. is the definition plane before or behind the source. The product of signumZ and signumKz ( \(\operatorname{sgn}(z) \cdot \operatorname{sgn}(k_z)\)) determines if the phase is diverging or converging.
signumKzSign of the z-component of the k-vector of the harmonic field, i.e. whether propagation in positive or negative z-direction is considered. The product of signumZ and signumKz ( \(\operatorname{sgn}(radius) \cdot \operatorname{sgn}(k_z)\)) determines if the phase is diverging or converging.
Returns
The phase as real value with double precision.

◆ SphericalPhaseDerivative()

static VectorD SphericalPhaseDerivative ( VectorD  position,
double  k,
double  radius,
double  signumZ,
double  signumKz 
)
static

Calculates the first derivative of spherical phase function (not a complex number but just the phase value). The spherical phase function is defined as \(f(\boldsymbol{r}) = \exp{(signumZ * signumKz * k * a)}\) with \(a = \sqrt{(x^2 + y^2 + z^2)}\).

Parameters
positionPosition \(\boldsymbol{r}\) spherical phase is to be calculated for.
kAbsolute value of the wave vector \(k\).
radiusDistance \(z\) from the source plane of the spherical phase function.
signumZSign of the spherical phase radius, i.e. is the definition plane before or behind the source. The product of signumZ and signumKz ( \(\operatorname{sgn}(z) \cdot \operatorname{sgn}(k_z)\)) determines if the phase is diverging or converging.
signumKzSign of the z-component of the k-vector of the harmonic field, i.e. whether propagation in positive or negative z-direction is considered. The product of signumZ and signumKz ( \(\operatorname{sgn}(radius) \cdot \operatorname{sgn}(k_z)\)) determines if the phase is diverging or converging.
Returns
Result of operation.

◆ SphericalPhaseFunction()

static Complex SphericalPhaseFunction ( VectorD  position,
double  k,
double  radius,
double  signumZ,
double  signumKz 
)
static

Calculates the value of a spherical phase function on the position \(\boldsymbol{r}\). The spherical phase function is defined as \(f(\boldsymbol{r}) = \exp{(\text{signumZ} \cdot \text{signumKz} \cdot k \cdot a)}\) with \(a = \sqrt{(x^2 + y^2 + z^2)}\).

Parameters
positionPosition \(\boldsymbol{r}\) spherical phase is to be calculated for.
kAbsolute value of the wave vector \(k\).
radiusDistance \(z\) from the source plane of the spherical phase function.
signumZSign of the spherical phase radius, i.e. is the definition plane before or behind the source. The product of signumZ and signumKz ( \(\operatorname{sgn}(z) \cdot \operatorname{sgn}(k_z)\)) determines if the phase is diverging or converging.
signumKzSign of the z-component of the k-vector of the harmonic field, i.e. whether propagation in positive or negative z-direction is considered. The product of signumZ and signumKz ( \(\operatorname{sgn}(radius) \cdot \operatorname{sgn}(k_z)\)) determines if the phase is diverging or converging.
Returns
Result of operation.

◆ SymDefSolve()

static void SymDefSolve ( double  matr[,],
ref double[]  vect 
)
static

Solves the linear system matr * x = vect by using the Cholesky decomposition of matr.

Parameters
matrA two dimensional coefficients matrix. The matrix must be symmetric and positive definite.
vectIn the function call this parameter must contain the function values vector of the equation system. After the evaluation of the function this parameter contains the solution vector x.

◆ Tan()

static double Tan ( double  d)
static

Special tangent function as the Math.Tan function has problems with \(\tan\left(\frac{\pi}{2}\right)\) and \(\tan\left(\pi\right)\).

Parameters
dThe argument of the tangent.
Returns
The tangent of d.

◆ ToThePowerOf()

static double ToThePowerOf ( this double  baseNumber,
double  exponent 
)
static

Raises the double number to the given power.

Parameters
baseNumberThe base.
exponentThe exponent.
Returns
The double number to the power of the exponent.

◆ TriangleNumber()

static int TriangleNumber ( int  index)
static

Calculates the ith triangle number which is i * (i+1) / 2.

Parameters
indexThe index of the triangle number to calculate.
Returns
The ith triangle number