SSJ
V. 1.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(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 evaluated at z.
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)
          .
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.
static double simpsonIntegral(MathFunction func, double a, double b, int numIntervals)
          Computes and returns an approximation of the integral of func over [a, b], using the Simpsons 1/3 method with numIntervals intervals.
 
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.

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.

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)
. Given the n + 1 distinct points (x0, y0),(x1, y1),…,(xn, yn) [with X[0] = xi and similarly for Y and C], this function computes the n + 1 coefficients C[i] of the Newton interpolating polynomial P(x) of degree n passing through these points:

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 evaluated at z.

Parameters:
n - degree of the interpolating polynomial
X - x-coordinates of points
C - Coefficients of the interpolating polynomial
z - x-coordinate where polynomial is evaluated

simpsonIntegral

public static double simpsonIntegral(MathFunction func,
                                     double a,
                                     double b,
                                     int numIntervals)
Computes and returns an approximation of the integral of func over [a, b], using the Simpsons 1/3 method with numIntervals intervals. This method estimates

abf (x)dx,

where f (x) is the function defined by func and evaluated at x, by dividing [a, b] in n = numIntervals interval with length h = (b - a)/n. The integral is estimated by

$\displaystyle {\frac{{h}}{{3}}}$(f (a) + 4f (a + h) + 2f (a + 2h) + 4f (a + 3h) + ... + f (b))

This method assumes that a <= b < ∞, and n is even.

Parameters:
func - the function being integrated.
a - the left bound
b - the right bound.
numIntervals - the number of intervals.
Returns:
the approximate value of the integral.

SSJ
V. 1.2.5.

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