umontreal.iro.lecuyer.util
Class Misc
- java.lang.Object
-
- umontreal.iro.lecuyer.util.Misc
-
public class Misc extends java.lang.ObjectThis class provides miscellaneous functions that are hard to classify. Some may be moved to another class in the future.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doubleevalPoly(double[] C, int n, double x)Evaluates the polynomialstatic doubleevalPoly(int n, double[] X, double[] C, double z)Given n, X and C as described ininterpol(n, X, Y, C), this function returns the value of the interpolating polynomial P(z) evaluated at z (see eq.static intgetTimeInterval(double[] times, int start, int end, double t)Returns the index of the time interval corresponding to time t.static voidinterpol(int n, double[] X, double[] Y, double[] C)Computes the Newton interpolating polynomial.static doublequickSelect(double[] t, int n, int k)Returns the kth smallest item of the array t of size n.static intquickSelect(int[] t, int n, int k)Returns the kth smallest item of the array t of size n.
-
-
-
Method Detail
-
quickSelect
public static double quickSelect(double[] t, int n, int k)Returns the kth smallest item of the array t of size n. Array t is unchanged by the method.- Parameters:
t- the array which contain the itemsn- the number of items in the arrayk- the index of the smallest item- Returns:
- the kth smallest item of the array t
-
quickSelect
public static int quickSelect(int[] t, int n, int k)Returns the kth smallest item of the array t of size n. Array t is unchanged by the method.- Parameters:
t- the array which contain the itemsn- the number of items in the arrayk- the index of the smallest item- Returns:
- the kth smallest item of the array t
-
getTimeInterval
public static int getTimeInterval(double[] times, int start, int end, double t)Returns the index of the time interval corresponding to time t. Let t0 <= ... <= tn be simulation times stored in a subset of times. This method uses binary search to determine the smallest value i for which ti <= t < ti+1, and returns i. The value of ti is stored in times[start+i] whereas n is defined as end - start. If t < t0, this returns -1. If t >= tn, this returns n. Otherwise, the returned value is greater than or equal to 0, and smaller than or equal to n - 1. start and end are only used to set lower and upper limits of the search in the times array; the index space of the returned value always starts at 0. Note that if the elements of times with indices start, ..., end are not sorted in non-decreasing order, the behavior of this method is undefined.- Parameters:
times- an array of simulation times.start- the first index in the array to consider.end- the last index (inclusive) in the array to consider.t- the queried simulation time.- Returns:
- the index of the interval.
- Throws:
java.lang.NullPointerException- if times is null.java.lang.IllegalArgumentException- if start is negative, or if end is smaller than start.java.lang.ArrayIndexOutOfBoundsException- if start + end is greater than or equal to the length of times.
-
interpol
public static void interpol(int n, double[] X, double[] Y, double[] C)Computes the Newton interpolating polynomial. Given the n + 1 real distinct points (x0, y0), (x1, y1),…,(xn, yn), with X[i] = xi, Y[i] = yi, this function computes the n + 1 coefficients C[i] = ci of the Newton interpolating polynomial P(x) of degree n passing through these points, i.e. such that yi = P(xi), given by- Parameters:
n- degree of the interpolating polynomialX- x-coordinates of pointsY- y-coordinates of pointsC- Coefficients of the interpolating polynomial
-
evalPoly
public static double evalPoly(int n, double[] X, double[] C, double z)Given n, X and C as described ininterpol(n, X, Y, C), this function returns the value of the interpolating polynomial P(z) evaluated at z (see eq. ).- Parameters:
n- degree of the interpolating polynomialX- x-coordinates of pointsC- Coefficients of the interpolating polynomialz- argument where polynomial is evaluated- Returns:
- Value of the interpolating polynomial P(z)
-
-
DMelt 3.0 © DataMelt by jWork.ORG