Class MathHelper
java.lang.Object
net.simplace.core.service.MathHelper
Static helper methods for aggregating lists of numbers (MIN, MAX, AVG, SUM, COUNT), element-wise array arithmetic,
Gauss-Legendre integration and linear regression.
- Author:
- XPMUser
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Double[]Adds two arrays element by element.static Integer[]Adds two arrays element by element.static NumberAVG(LinkedList aLinkedList, FWSimVariable.DATA_TYPE aDataType, int i) Calculates the average of a list of values.static voidcalculateLinearRegression(int ind, double[] x, double[] y, FWSimVariable<Double> aRegressionM, FWSimVariable<Double> aRegressionB) Calculates a least-squares linear regressiony = m * x + band stores slope and intercept in the given variables.static voidcalulateLinearRegression(int ind, double[] x, double[] y, FWSimVariable<Double> aRegressionM, FWSimVariable<Double> aRegressionB) Deprecated.static IntegerCOUNT(LinkedList aLinkedList) Counts the non-nullentries of a list.static doubleGaussIntegrationWeight(int n, int i) Returns a weight for Gauss-Legendre integration.static doubleGaussIntegrationX(int n, int i) Returns an integration point (x-value in [-1, 1]) for Gauss-Legendre integration.static NumberMAX(LinkedList aLinkedList, int i) Calculates the maximum of a list of values.static NumberMIN(LinkedList aLinkedList, int i) Calculates the minimum of a list of values.static Double[]Multiplies an array either by a scalar or element by element by a second array.static Integer[]Multiplies an array either by a scalar or element by element by a second array.static NumberSUM(LinkedList aLinkedList, FWSimVariable.DATA_TYPE aDataType, int i) Calculates the sum of a list of values.
-
Constructor Details
-
MathHelper
public MathHelper()
-
-
Method Details
-
MAX
Calculates the maximum of a list of values.nullentries are skipped. The data type is determined from the first entry of the list.- Parameters:
aLinkedList- list of values, either numbers or (ifi > -1)Double[]orInteger[]arraysi- index of the array element to use if the list contains arrays;-1if the list contains plain numbers- Returns:
- the maximum, or
nullif the list isnull, empty or contains values of an unsupported type
-
MIN
Calculates the minimum of a list of values.nullentries are skipped. The data type is determined from the first entry of the list.- Parameters:
aLinkedList- list of values, either numbers or (ifi > -1)Double[]orInteger[]arraysi- index of the array element to use if the list contains arrays;-1if the list contains plain numbers- Returns:
- the minimum, or
nullif the list isnull, empty or contains values of an unsupported type
-
AVG
Calculates the average of a list of values.nullentries are skipped and do not count as values. For integer data the average is rounded to the nearest integer.- Parameters:
aLinkedList- list of values, either numbers orDouble[]/Integer[]arraysaDataType- data type of the list entries (DOUBLE, INT, DOUBLEARRAY or INTARRAY)i- index of the array element to use if the list contains arrays;-1otherwise- Returns:
- the average (
DoubleorInteger), ornullif the list isnullor empty
-
SUM
Calculates the sum of a list of values.nullentries are skipped.- Parameters:
aLinkedList- list of values, either numbers orDouble[]/Integer[]arraysaDataType- data type of the list entries (DOUBLE, INT, DOUBLEARRAY or INTARRAY)i- index of the array element to use if the list contains arrays;-1otherwise- Returns:
- the sum, or
nullif the list isnullor empty
-
COUNT
Counts the non-nullentries of a list.- Parameters:
aLinkedList- list of values- Returns:
- the number of non-
nullentries, ornullif the list isnullor empty
-
ADD
public static Double[] ADD(Double[] aFirstObjectToCalculateWith, Double[] aSecondObjectToCalculateWith) Adds two arrays element by element. The result is written into the first array.- Parameters:
aFirstObjectToCalculateWith- first summand; modified in place and returnedaSecondObjectToCalculateWith- second summand; must be at least as long as the first array- Returns:
- the first array, now containing the element-wise sums
-
ADD
public static Integer[] ADD(Integer[] aFirstObjectToCalculateWith, Integer[] aSecondObjectToCalculateWith) Adds two arrays element by element. The result is written into the first array.- Parameters:
aFirstObjectToCalculateWith- first summand; modified in place and returnedaSecondObjectToCalculateWith- second summand; must be at least as long as the first array- Returns:
- the first array, now containing the element-wise sums
-
MULTIPLY
public static Double[] MULTIPLY(Double[] aFirstObjectToCalculateWith, Object aSecondObjectToCalculateWith) Multiplies an array either by a scalar or element by element by a second array. The result is written into the first array.- Parameters:
aFirstObjectToCalculateWith- array to multiply; modified in place and returnedaSecondObjectToCalculateWith- aNumber(scalar factor) or aDouble[]of at least the same length; other types leave the array unchanged- Returns:
- the first array, now containing the products
-
MULTIPLY
public static Integer[] MULTIPLY(Integer[] aFirstObjectToCalculateWith, Object aSecondObjectToCalculateWith) Multiplies an array either by a scalar or element by element by a second array. The result is written into the first array. A scalar factor is truncated to an integer before multiplying.- Parameters:
aFirstObjectToCalculateWith- array to multiply; modified in place and returnedaSecondObjectToCalculateWith- aNumber(scalar factor) or anInteger[]of at least the same length; other types leave the array unchanged- Returns:
- the first array, now containing the products
-
GaussIntegrationWeight
public static double GaussIntegrationWeight(int n, int i) Returns a weight for Gauss-Legendre integration.- Parameters:
n- number of integration points (1 to 5)i- zero-based index of the weight (0 ton-1)- Returns:
- the weight, or 0 if
noriis out of range
-
GaussIntegrationX
public static double GaussIntegrationX(int n, int i) Returns an integration point (x-value in [-1, 1]) for Gauss-Legendre integration.- Parameters:
n- number of integration points (1 to 5)i- zero-based index of the point (0 ton-1)- Returns:
- the x-value, or 0 if
noriis out of range
-
calulateLinearRegression
@Deprecated public static void calulateLinearRegression(int ind, double[] x, double[] y, FWSimVariable<Double> aRegressionM, FWSimVariable<Double> aRegressionB) Deprecated.Calculates a least-squares linear regressiony = m * x + band stores slope and intercept in the given variables. Range errors while setting the values are logged, not thrown.- Parameters:
ind- number of data points to use fromxandyx- x-valuesy- y-valuesaRegressionM- receives the calculated slope maRegressionB- receives the calculated intercept b
-
calculateLinearRegression
public static void calculateLinearRegression(int ind, double[] x, double[] y, FWSimVariable<Double> aRegressionM, FWSimVariable<Double> aRegressionB) Calculates a least-squares linear regressiony = m * x + band stores slope and intercept in the given variables. Range errors while setting the values are logged, not thrown.- Parameters:
ind- number of data points to use fromxandyx- x-valuesy- y-valuesaRegressionM- receives the calculated slope maRegressionB- receives the calculated intercept b
-
calculateLinearRegression(int, double[], double[], FWSimVariable, FWSimVariable)