本文介绍一下mathematica里面nearest函数的用法.先给出一组数据: a = {76, 85, 73, 51, 55, 85, 62, 77, 78, 54, 83, 40, 68, 2, 69, 87, 4, 44, 21, 10, 73, 30, 78, 48, 0, 25, 88, 12, 47, 29, 89, 48, 9, 97, 49, 54, 34, 49, 43, 28, 71, 98, 7, 3, 98, 1, 26, 91, 82, 66, 2, 30, 68, 74, 95, 39, 30, 45, 18, 67, 47, 56, 45, 62, 93, 97, 44, 67, 59, 45, 86, 35, 55, 5, 53, 27, 40, 71, 13, 49, 43, 75, 18, 48, 73, 14, 70, 39, 45, 2, 21, 62, 29, 12, 5, 74, 1, 93, 100}; 然后找出离39最近的数据: nearest[a, 39]找出离39最近的3个元素: nearest[a, 39,3] 数目不足的时候,会用稍远一点的数据顶位.分别找出到8, 19, 30, 56最近的元素: nearest[a, {8, 19, 30, 56}]给出平面上的10个随机点的坐标: a = randomreal[{0, 10}, {10, 2}] 从里面找出到{-2,3}最近的点.在平面上画出这些点,可以形象的看到,绿色点是距离红色点最近的点,比其它蓝色点都要近. graphics[{pointsize[0.03], bl e, point[a], red, point[{-2, 3}], green,point[b]}]随机的给出若干颜色,并找出最接近蓝色的颜色.