SSJ
V. 2.6.

umontreal.iro.lecuyer.util
Class Misc

java.lang.Object
  extended by umontreal.iro.lecuyer.util.Misc

public class Misc
extends Object

This class provides miscellaneous functions that are hard to classify. Some may be moved to another class in the future.


Method Summary
static double evalPoly(double[] C, int n, double x)
          .
static double evalPoly(int n, double[] X, double[] C, double z)
          Given n, X and C as described in interpol(n, X, Y, C), this function returns the value of the interpolating polynomial P(z) evaluated at z (see eq.
static double getMedian(double[] A, int n)
          Returns the median of the first n elements of array A.
static double getMedian(int[] A, int n)
          Returns the median of the first n elements of array A.
static int getTimeInterval(double[] times, int start, int end, double t)
          Returns the index of the time interval corresponding to time t.
static void interpol(int n, double[] X, double[] Y, double[] C)
          Computes the Newton interpolating polynomial.
static double quickSelect(double[] A, int n, int k)
          Returns the kth smallest item of the array A of size n.
static int quickSelect(int[] A, int n, int k)
          Returns the kth smallest item of the array A of size n.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

quickSelect

public static double quickSelect(double[] A,
                                 int n,
                                 int k)
Returns the kth smallest item of the array A of size n. Array A is unchanged by the method. Restriction: 1 <= k <= n.

Parameters:
A - the array which contain the items
n - the number of items in the array
k - the index of the smallest item
Returns:
the kth smallest item of the array A

quickSelect

public static int quickSelect(int[] A,
                              int n,
                              int k)
Returns the kth smallest item of the array A of size n. Array A is unchanged by the method. Restriction: 1 <= k <= n.

Parameters:
A - the array which contain the items
n - the number of items in the array
k - the index of the smallest item
Returns:
the kth smallest item of the array A

getMedian

public static double getMedian(double[] A,
                               int n)
Returns the median of the first n elements of array A.

Parameters:
A - the array
n - the number of used elements
Returns:
the median of A

getMedian

public static double getMedian(int[] A,
                               int n)
Returns the median of the first n elements of array A.

Parameters:
A - the array
n - the number of used elements
Returns:
the median of A

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:
NullPointerException - if times is null.
IllegalArgumentException - if start is negative, or if end is smaller than start.
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

        P(x) = c0 + c1(x - x0) + c2(x - x0)(x - x1) + ... + cn(x - x0)(x - x1) ... (x - xn-1).

Parameters:
n - degree of the interpolating polynomial
X - x-coordinates of points
Y - y-coordinates of points
C - 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 in interpol(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 polynomial
X - x-coordinates of points
C - Coefficients of the interpolating polynomial
z - argument where polynomial is evaluated
Returns:
Value of the interpolating polynomial P(z)

evalPoly

public static double evalPoly(double[] C,
                              int n,
                              double x)
. Evaluates the polynomial P(x) of degree n with coefficients cj = C[j] at x:

        P(x) = c0 + c1x + c2x2 + ... + cnxn

Parameters:
C - Coefficients of the polynomial
n - degree of the polynomial
x - argument where polynomial is evaluated
Returns:
Value of the polynomial P(x)

SSJ
V. 2.6.

To submit a bug or ask questions, send an e-mail to Pierre L'Ecuyer.