Nearest的用法(Mathematica)

本文介绍一下Mathematica里面Nearest函数的用法。

工具/原料

  • 电脑
  • Mathematica

方法/步骤

  1. 1

    先给出一组数据:

    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]

    d3c39889a146b7b12ec4de0ec77c34b33d413591.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  2. 2

    找出离39比来的3个元素:

    Nearest[A, 39,3]

    数量不足的时辰,会用稍远一点的数据顶位。

    b6f0f0f97fbd4c7cf78e9df2b8bad341027d3091.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  3. 3

    别离找出到8, 19, 30, 56比来的元素:

    Nearest[A, {8, 19, 30, 56}]

    efb861bd4c7c34b3f87c92095841037de0373191.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  4. 4

    给出平面上的10个随机点的坐标:

    A = RandomReal[{0, 10}, {10, 2}]

    从内里找出到{-2,3}比来的点。

    7efc527c34b33c41f68772f2887de137c8762e91.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  5. 5

    在平面上画出这些点,可以形象的看到,绿色点是间隔红色点比来的点,比其它蓝色点都要近。

    Graphics[{PointSize[0.03], 

    Blue, Point[A], 

    Red, Point[{-2, 3}], 

    Green,Point[B]}]

    35f2224133bad341c4404084427622bc7cc52c91.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  6. 6

    随机的给出若干颜色,并找出最靠近蓝色的颜色。

    Nearest[A, Blue]

    3d002dbad341037d290a68c5a9bc7dc5ce672d91.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80
  7. 7

    找出前三个比力靠近蓝色的颜色:

    Nearest[A, Blue,3]

    32fbcd41037de137004b830ff6c5cf672a5f2a91.jpg?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_500%2Climit_1%2Fformat%2Cf_auto%2Fquality%2Cq_80END
  • 发表于 2022-08-22 20:02
  • 阅读 ( 177 )
  • 分类:其他类型

相关问题

0 条评论

请先 登录 后评论