SSJ
V. 2.5.

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 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[] t, int n, int k)
          Returns the kth smallest item of the array t of size n.
static int quickSelect(int[] t, int n, int k)
          Returns the kth smallest item of the array t 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[] 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 items
n - the number of items in the array
k - 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 items
n - the number of items in the array
k - 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:
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) = c0 + c1x + c2x2 + ... + cnxn

of degree n with coefficients cj = C[j] at x.

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.5.

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