MathUtil Class

Collection of static methods used in Mike1D.

Definition

Namespace: DHI.Mike1D.Generic
Assembly: DHI.Mike1D.Generic (in DHI.Mike1D.Generic.dll) Version: 24.0.0.0 (11.1.1.1111)
C#
public static class MathUtil
Inheritance
Object    MathUtil

Methods

AllPositive(Double, Int32) Checks if vector xTable has all positive elements
AllPositive(Double, Int32, Int32) Checks if vector xTable has all positive elements
AllZero Checks if vector xTable has all zero elements
AreEqualRel Returns true if a and b are equal within a relative tolerance.
Derivative Calculates the derivative of the yTable versus xTable at x. The xTable must be either monoton increasing or monoton decreasing array. The method applied when the argument is outside the interval corresponds to the exrapolationmethod.nearest, i.e derivative equals zero.
Derivatives This procedure calculates the derivative of vector yTable with respect to the monoton and increasing vector xTable. The lengt of the yTable and xTable vectors must be equal and at least equal to 2.
DiffersFrom(Double, Double) Returns true if the values differ, i.e. v1 != v2 Use this to avoid warnings in double value comparisons
DiffersFrom(Single, Single) Returns true if the values differ, i.e. v1 != v2 Use this to avoid warnings in double value comparisons
DivOrZero This functions will make a division. If the denominator equals zero the function returns zero.
ExactEquals(Double, Double) Returns true if the values equals, i.e. v1 == v2 Use this to avoid warnings in double value comparisons
ExactEquals(Single, Single) Returns true if the values equals, i.e. v1 == v2 Use this to avoid warnings in double value comparisons
FixBetweenLimits Function that ensures that a value (the variable arg) is located within certain limits. if the value is lower than the low limit (the variable LowLimit) this function returns LowLimit. If the value is higher than the high limit (the variable HighLimit) the function returns HighLimit. Otherwise the value is returned.
GetIndeces(DateTime, DateTime, Int32, Int32, Boolean) Finds the two indexes in a mononton vector using bisection search. This can handle as well increasing as decreasing vectors, as long as they are monotone. The indexes corresponds to the points neighbouring the argument, arg. In case of an exact match the two indexes will be identical. If the argument is outside the valid interval either the lower or the upper interval boundary is returned depending on wheter the argument is lower or higher than the lower or upper boundary, respectively.
GetIndeces(Double, MathUtilIDataToInterpolate, Int32, Int32, Boolean) Finds the two indexes in a mononton vector using bisection search. This can handle as well increasing as decreasing vectors, as long as they are monotone. The indexes corresponds to the points neighbouring the argument, arg. In case of an exact match the two indexes will be identical. If the argument is outside the valid interval either the lower or the upper interval boundary is returned depending on wheter the argument is lower or higher than the lower or upper boundary, respectively.
GetIndeces(Double, Double, Int32, Int32, Boolean) Finds the two indexes in a mononton vector using bisection search. This can handle as well increasing as decreasing vectors, as long as they are monotone. The indexes corresponds to the points neighbouring the argument, arg. In case of an exact match the two indexes will be identical. If the argument is outside the valid interval either the lower or the upper interval boundary is returned depending on wheter the argument is lower or higher than the lower or upper boundary, respectively.
GetInterval(Double, Double, Double)

Finds the interval in a vector where the argument lays in between. Assumes that the vector has at least two elements.

The vector must increase strictly monotonically. If argument is below the first value, 0 is returned. If argument is above last value, the length of the vector is returned.

The result is the interval number, one based, meaning that the arg fullfills: (vector[res-1] < arg && arg <= vector[res])

Also the scale factor for interpolating is returned. For linear interpolation arg = vector[res-1] + fraction*(vector[res]-vector[res-1]) or arg = (1-fraction)*vector[res-1] + fraction*vector[res]

If arg exists in vector, the result is such that arg = vector[res] i.e., fraction is one (except when arg = vector[0], then res = 1 and fraction = 0).

GetInterval(DateTime, IReadOnlyListDateTime, Double, Int32)GetInterval(Double, Double, Double, Int32) for DateTimes. This has an IReadOnlyListT DateTime as argument instead of a DateTime[]. which is slower than a DateTime[] version
GetInterval(Double, MathUtilIDataForSearching, Double, Int32)GetInterval(Double, Double, Double, Int32) for details. This has an MathUtilIDataForSearching as argument instead of a double[]. This version is slower than the double[] version.
GetInterval(Double, IListDouble, Double, Int32)GetInterval(Double, Double, Double, Int32) for details. This has an IListT as argument instead of a double[]. This version is slower than the double[] version.
GetInterval(Double, ListDouble, Double, Int32)GetInterval(Double, Double, Double, Int32) for details. This has an ListT as argument instead of a double[]. This version is slower than the double[] version
GetInterval(Double, Double, Double, Int32) Finds the interval in a vector where the argument lays in between. Searches the last interval first. It is assumed that the input vector has at least two elements. This uses binary search techniques for efficiency. The vector must increase strictly monotonically. If argument is below the first value, 0 is returned. If argument is above last value, the length of the vector is returned. The result is the interval number, one based, meaning that the arg fullfills: (vector[res-1] < arg && arg <= vector[res]) Also the scale factor for interpolating is returned. For linear interpolation arg = vector[res-1] + fraction*(vector[res]-vector[res-1]) or arg = (1-fraction)*vector[res-1] + fraction*vector[res] If arg exists in vector, the result is such that arg = vector[res] i.e., fraction is one (except when arg = vector[0], then res = 1 and fraction = 0).
GetInterval(Double, Int32, FuncInt32, Double, Double)

Finds the interval in a vector where the argument lays in between. Assumes that the vector has at least two elements.

The vector must increase strictly monotonically. If argument is below the first value, 0 is returned. If argument is above last value, the length of the vector is returned.

The result is the interval number, one based, meaning that the arg fullfills: (vector[res-1] < arg && arg <= vector[res])

Also the scale factor for interpolating is returned. For linear interpolation arg = vector[res-1] + fraction*(vector[res]-vector[res-1]) or arg = (1-fraction)*vector[res-1] + fraction*vector[res]

If arg exists in vector, the result is such that arg = vector[res] i.e., fraction is one (except when arg = vector[0], then res = 1 and fraction = 0).

GetInterval(Double, Int32, FuncInt32, Double, Double, Int32)

Finds the interval in a vector where the argument lays in between. Assumes that the vector has at least two elements.

The vector is represented by the vectorValue function, which must return vector values in strictly increasing order.

The vector must increase strictly monotonically. If argument is below the first value, 0 is returned. If argument is above last value, the length of the vector is returned.

The result is the interval number, one based, meaning that the arg fullfills: (vector[res-1] < arg && arg <= vector[res])

Also the scale factor for interpolating is returned. For linear interpolation arg = vector[res-1] + fraction*(vector[res]-vector[res-1]) or arg = (1-fraction)*vector[res-1] + fraction*vector[res]

If arg exists in vector, the result is such that arg = vector[res] i.e., fraction is one (except when arg = vector[0], then res = 1 and fraction = 0).

GetIntervalT(Double, T, FuncT, Double, Double)

Finds the interval in a vector where the argument lays in between. Assumes that the vector has at least two elements.

The vector must increase strictly monotonically. If argument is below the first value, 0 is returned. If argument is above last value, the length of the vector is returned.

The result is the interval number, one based, meaning that the arg fullfills: (vector[res-1] < arg && arg <= vector[res])

Also the scale factor for interpolating is returned. For linear interpolation arg = vector[res-1] + fraction*(vector[res]-vector[res-1]) or arg = (1-fraction)*vector[res-1] + fraction*vector[res]

If arg exists in vector, the result is such that arg = vector[res] i.e., fraction is one (except when arg = vector[0], then res = 1 and fraction = 0).

GetIntervalT(T, MathUtilIDataForSearchingT, Double, Int32)GetInterval(Double, Double, Double, Int32) for details. This has an MathUtilIDataForSearchingT as argument instead of a double[]. This version is slower than an array version.
GetIntervalU Unsafe version of GetInterval(Double, Double, Double, Int32)
Interp(Double, MathUtilIDataToInterpolate, ExtrapolationTypes) 1-D linear interpolation (table lookup) Interpolates to find y, the value of the underlying function yTable at the point x. xTable must be a monoton increasing array of the same length as yTable. For x values outside xTable extrapolation is applied. Extrapolation method is specified.
Interp(Double, Double, Double) 1-D linear interpolation (table lookup) Interpolates to find y, the value of the underlying function yTable at the point x. xTable must be a monoton increasing array of the same length as yTable.
Interp(DateTime, DateTime, Double, ExtrapolationTypes) 1-D linear interpolation (table lookup) Interpolates to find y, the value of the underlying function yTable at the point x. xTable must be a monoton increasing array of the same length as yTable. For x values outside xTable extrapolation is applied. Extrapolation method is specified.
Interp(Double, Double, Double, ExtrapolationTypes) 1-D linear interpolation (table lookup) Interpolates to find y, the value of the underlying function yTable at the point x. xTable must be a monoton increasing array of the same length as yTable. For x values outside xTable extrapolation is applied. Extrapolation method is specified.
Interp(DateTime, DateTime, Double, DateTime, Double) Interpolates linearly between two points (t1, y1) and (t2, y2) and returns function value y at t.
Interp(Double, Double, Double, Double, Double) Interpolates linearly between two points (x1, y1) and (x2, y2) and returns function value y at x.
Interpn(Double, Double, Double) 1-D linear interpolation (table lookup) Interpolates to find y, the value of the underlying function yTable at the point x. xTable must be a monoton increasing array of the same length as yTable.
Interpn(Double, Double, Double, ExtrapolationTypes) 
InterpolateRowsInTable Looks the argument, x, up in the rowheader, xTable, of a table, table. Hereby the row numbers used for the interpolation is determined. In case of an exact match the indexes are identical. No extrapolations is used which implicitly corresponds to the extraplation type 'Nearest'.
InterpolateTable Interpolate an XYtable
Limit Limit a value between min and max
Linspace Return evenly spaced numbers over a specified interval.
Max Determines the maximum value contained in the vector x.
Min Determines the minimum value contained in the vector x.
MonotonicallyDecreasingOrConstant Checks if vector xTable is monoton and decreasing or constant
MonotonicallyIncreasingOrConstant Checks if vector xTable is monoton and increasing or constant
MonotonouslyDecreasingOrConstant Checks if vector xTable is monoton and decreasing or constant
PrepareIndexesForDerivation Returns the indexes used to make a derivative. As input is used the indexes found in GetIndeces and the total number of entries in the array.
Round(Double, Double) Round down value to number of significant digits.

The numSignificantDigits is a log10 number, i.e. it can be used to remove insignificant digits only for small numbers, i.e. . Round(19, System.Math.Log10(20) = 19 - no rounding Round(20, System.Math.Log10(20) = 20 - on the boundary of rounding Round(21, System.Math.Log10(20) = 20 - rounding Round(31, System.Math.Log10(20) = 30 - rounding

Round(Int32, Double) Round down integer value to number of significant digits.

The numSignificantDigits is a log10 number, i.e. it can be used to remove insignificant digits only for small numbers, i.e. . Round(19, System.Math.Log10(20) = 19 - no rounding Round(20, System.Math.Log10(20) = 20 - on the boundary of rounding Round(21, System.Math.Log10(20) = 20 - rounding Round(31, System.Math.Log10(20) = 30 - rounding

Sqr Square function.
StrictlyMonoton Checks if vector xTable is strictly monoton and increasing
StrictlyMonotonIndex(Double) Checks if vector xTable is strictly monoton and increasing
StrictlyMonotonIndexT(T, ComparisonT) Checks if vector xTable is strictly monoton and increasing
SurfaceAreaOfPartialCone Return the surface area of a partial cone given the volume and one surface areas.
VolumeOfPartialCone Return the volume of a partial cone of a given height and surface areas.

Fields

Degrees2Radians Constant for converting degrees to radians
Radian2Degrees Constant for converting radians to degrees

See Also