help mata mm_locate()-------------------------------------------------------------------------------

Title

mm_locate() -- Search an ordered vector

Syntax

voidmm_locate(y,x,j)

voidmm_hunt(y,x,j)where

y:numeric vectorcontaining data;ymust be ordered, either ascending or descending

x:numeric scalarcontaining value to be located iny

j:real scalarcontaining initial guess formm_hunt(); will be replaced by areal scalarsuch thatxlies betweeny[j] andy[j+1]

DescriptionGiven an ordered data vector

yand some valuex,mm_locate(), replacesjsuch thatxlies betweeny[j] andy[j+1].j==0 orj==length(y) is returned, ifxis out of range.mm_locate()applies the bisection method to locatexiny.

mm_hunt()also locatesxiny. However,mm_hunt()uses the input value ofjas the starting point for the search process and applies a modified algorithm.mm_hunt()is useful if consecutive searches be performed for similar values.

mm_locate()is a translation of thelocatealgorithm in Press et al. (1992:117).mm_hunt()is a translation of thehuntalgorithm in Press et al. (1992:118-119).

RemarksNone.

Conformability

mm_locate(y,x,j),mm_hunt(y,x,j):input:y:n x1 or 1x nx: 1x1j: 1x1output:j: 1x1

DiagnosticsNone.

Source codemm_locate.mata

ReferencesPress, William H., Saul A. Teukolsky, William T. Vetterling, Brian P. Flannery (1992). Numerical Recipes in C. The Art of Scientific Computing. Second Edition. Cambridge University Press. http://www.numerical-recipes.com/

AuthorBen Jann, ETH Zurich, jann@soz.gess.ethz.ch

Also see