Show 

                

nearest

(function for equations)

 

Usage:

nearest0 (val, x0, x1, ... xn)

nearest1 (val, x1, x2, ... xn)

Definition:

i s.t. (|val - xi| ⋜ |val - xj|) for all j

Required:

val and xi are unrestricted reals

Returns the index (position in list) of the argument with the value closest to val (as measured by the absolute value of the difference).  If there are several with the same smallest difference, then the index of the first occurrence will be returned.  The first x argument has index 0 if nearest0 is used, or index 1 if nearest1 is used.

Must be passed at least 2 arguments (val and an x).

For the inverse function, see select.

See also member.

 

Examples:

nearest0 (1, 1, 3.4, 1, 3.4)     returns 0

 

nearest1 (5e3, -6.6, -3.4, 126)  returns 3

 

 

Home > Special Math Functions_nearest