This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

Nearest

Nearest
gives the list of to which x is nearest.
Nearest
gives the corresponding to the to which x is nearest.
Nearest
gives the same result.
Nearest[{elem1, elem2, ...}->Automatic, x]
takes the to be successive integers i.
Nearest
gives the n nearest to x.
Nearest[data]
generates a NearestFunction[...] which can be applied repeatedly to different x.
  • If the are vectors or matrices of numbers, Nearest by default in effect uses the metric Norm[#1-#2]&.
  • For strings, Nearest by default uses the edit distance metric.
  • The following option can be given:
DistanceFunctionAutomaticthe distance metric to use
  • When several elements are returned, the nearest ones are given first.
  • If several elements are at the same distance, they are returned in the order they appear in data.
Find the element nearest to 20:
Find the 3 elements nearest to 20:
Find which element is nearest to in 2D:
Find "nearest" strings:
Find the element nearest to 20:
In[1]:=
Click for copyable input
Out[1]=
Find the 3 elements nearest to 20:
In[2]:=
Click for copyable input
Out[2]=
 
Find which element is nearest to in 2D:
In[1]:=
Click for copyable input
Out[1]=
 
Find "nearest" strings:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Create a Voronoi diagram:
Use higher resolution:
Use a -norm ("taxicab distance"):
Highlight the 200 random points closest to the origin:
Use the "taxicab" metric:
Create a nearest function from all the words in a dictionary:
Look up words closest to a given word:
Go further:
Find the outputs from running a sequence of elementary cellular automata:
Generate a complete list of outputs from all 256 elementary cellular automata:
Find which rules give outputs nearest the specified sequences:
Use a negative distance function to find the element farthest away from the given element:
Show the returned element for all values between 1 and 5:
Find successive nearest words in a dictionary:
New in 6