public class Numerical
extends java.lang.Object
minimum(double[])
, maximum(double[])
, and
vectorLength(double[])
.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ID
Class identification name with source code version and date.
|
Modifier and Type | Method and Description |
---|---|
static java.awt.geom.Point2D |
boxMuller()
Computes a pair of normally distributed random numbers using the Box-Muller
polar algorithm.
|
static double |
interpolate(double[] f,
double x)
Computes an interpolated value for the tabulated function f = f(x).
|
static double[] |
interpolate(double[] f,
double[] x)
Computes a one-dimensional array of linearly interpolated values for a
tabulated function f = f(x).
|
static void |
main(java.lang.String[] args)
Performs simple tests of the numerical analysis functions.
|
static double |
maximum(double[] values)
Finds the maximum value of an array of values.
|
static double |
minimum(double[] values)
Finds the minimum value of an array of values.
|
static double |
nearestElement(double[] array,
double value)
Finds the element of the input array nearest to the input value.
|
static double |
newtonCotes(double[] x,
double[] y)
Integrates the tabulated function y = y(x) using a five-point
Newton-Cotes method.
|
static double[] |
spline(double[] x,
double[] y)
Computes the second derivatives of the interpolating function for the
tabulated function y = f(x).
|
static double[] |
spline(double[] x,
double[] y,
double yp0,
double ypn_1)
Computes the second derivatives of the interpolating function for the
tabulated function y = f(x).
|
static double[] |
splint(double[] xa,
double[] ya,
double[] x)
Computes the cubic-spline interpolated values at x for the
tabulated function ya = f(xa).
|
static double |
splint(double[] xa,
double[] ya,
double[] y2,
double x)
Computes the cubic-spline interpolated value at x for the tabulated
function ya = f(xa).
|
static double[] |
splint(double[] xa,
double[] ya,
double yp0,
double ypn_1,
double[] x)
Computes the cubic-spline interpolated values at x for the
tabulated function ya = f(xa).
|
static double |
vectorLength(double[] v)
Computes the length of a vector.
|
static double |
vincentyInverse(double lon1,
double lat1,
double lon2,
double lat2)
Computes the distance between two points on Mars using the Vincenty inverse
formula.
|
public static final java.lang.String ID
public static double[] spline(double[] x, double[] y, double yp0, double ypn_1)
If either yp0 or ypn_1 (the first derivative of the
interpolating function at point 0 and n - 1, respectively)
is Double.MAX_VALUE
, the corresponding boundary condition is set for
a natural spline, with a second derivative of 0 on that boundary.
This function is adapted from the function spline in Numerical Recipes in C (1988).
x
- the points for which the tabulated function y has been
calculated.y
- the tabulated function for interpolation.yp0
- the first derivative of the interpolating function at point
0.ypn_1
- the first derivative of the interpolating function at point
n - 1.public static double[] spline(double[] x, double[] y)
This function is adapted from the function spline in Numerical Recipes in C (1988).
x
- the points for which the tabulated function y has been
calculated.y
- the tabulated function for interpolation.spline(double[], double[], double, double)
public static double splint(double[] xa, double[] ya, double[] y2, double x)
This function requires the second derivatives of the interpolating function,
which may be computed via the spline
function.
This function is adapted from the function splint in Numerical Recipes in C (1988).
xa
- the points for which the tabulated function ya has been
calculated.ya
- the tabulated function for interpolation.y2
- the second derivatives of the interpolating function; may be
computed via the spline
function.x
- the point at which to compute the interpolated value.public static double[] splint(double[] xa, double[] ya, double yp0, double ypn_1, double[] x)
The second derivatives of the interpolating function are computed via the
spline
function with the given first derivatives at point
0 and n - 1. If either derivative is Double.MAX_VALUE
, the corresponding boundary condition is set for a natural
spline, with a second derivative of 0 on that boundary.
This function is adapted from the function splint in Numerical Recipes in C (1988).
xa
- the points for which the tabulated function ya has been
calculated.ya
- the tabulated function for interpolation.yp0
- the first derivative of the interpolating function at point
0.ypn_1
- the first derivative of the interpolating function at point
n - 1.x
- the points at which to compute the interpolated values.public static double[] splint(double[] xa, double[] ya, double[] x)
The second derivatives of the interpolating function are computed via the
spline
function. The boundary points 0 and n -
1 of the interpolating function are set for a natural spline, with a
second derivative of 0 at those boundaries.
This function is adapted from the function splint in Numerical Recipes in C (1988).
xa
- the points for which the tabulated function ya has been
calculated.ya
- the tabulated function for interpolation.x
- the points at which to compute the interpolated values.public static double interpolate(double[] f, double x)
The function f is assumed to have been computed from a function f(x) at regular intervals from 0 to n - 1, where n is the length of the array f. Thus, f[0] is f(0), f[1] is f(1), and so on.
The returned value is computed such if x is outside the range 0, n - 1, it is set to the value of the nearest element of the array f. Otherwise it is linearly interpolated.
Example:
If f is {1.0, 2.0, 4.0}, then for x in {-0.5, 0.5, 1.75, 2.5}, interpolate(f, x) returns 1.0, 1.5, 3.5, and 4.0.
f
- a one-dimensional array of function values.x
- the point for interpolation.public static double[] interpolate(double[] f, double[] x)
The function f is assumed to have been computed from a function f(x) at regular intervals from 0 to n - 1, where n is the length of the array f. Thus, f[0] is f(0), f[1] is f(1), and so on.
The returned array of interpolated values is computed such that input values in the array x that are outside the range 0, n - 1 are set to the value of the nearest element of the array f. All other values are linearly interpolated.
Example:
If f is {1.0, 2.0, 4.0} and x is {-0.5, 0.5, 1.75, 2.5}, then interpolate(f, x) returns {1.0, 1.5, 3.5, 4.0}.
f
- a one-dimensional array of function values.x
- a one-dimensional array of points for interpolation.public static double newtonCotes(double[] x, double[] y)
cubic-spline interpolation
is used
in the integration to re-grid the function into regularly gridded segments.x
- the points for which the tabulated function y has been
calculated.y
- the tabulated function.public static double vincentyInverse(double lon1, double lat1, double lon2, double lat2)
lon1
- the first point's longitude in radians.lat1
- the first point's latitude in radians.lon2
- the second point's longitude in radians.lat2
- the second point's latitude in radians.public static double minimum(double[] values)
values
- the array of values.public static double maximum(double[] values)
values
- the array of values.public static double vectorLength(double[] v)
v
- the input vector.public static double nearestElement(double[] array, double value)
abs(ai - v)
where a is the input array and v is the input test value.
array
- the input array of values.value
- the test value.public static java.awt.geom.Point2D boxMuller()
This function uses the built-in Random
object to generate the
uniform distribution to be sampled.
The Box-Muller algorithm uses two input values to derive two output values.
The two output values are contained in a single Point2D
object for
convenience.
public static void main(java.lang.String[] args)
Compare the results of these tests with the equivalent calls of the IDL routines on which they're based.
Numerical
Command-line arguments are ignored.
args
- command-line arguments, ignored.Copyright \ (C) Arizona Board of Regents on behalf of the \ Planetary Image Research Laboratory, Lunar and \ Planetary Laboratory at the University of Arizona