Monte Carlo Simulation in Python || Approximating π using randomness !

Поделиться
HTML-код
  • Опубликовано: 20 окт 2024

Комментарии • 14

  • @robsonde
    @robsonde 11 месяцев назад +4

    The quality of Pi is directly driven by the precision of your floating point math.
    I did this in Pascal in 1991, and than again with C++ and got a much closer value because C++ had float64 not float32.
    The real magic is doing it on paper with a dice.

    • @YounesLab
      @YounesLab  11 месяцев назад

      Thank you for pointing that out, it is important to consider float-precision when dealing with such problems.

  • @ataractic
    @ataractic 11 месяцев назад +1

    simple but satisfying! nice explanation

  • @bommijn
    @bommijn 11 месяцев назад +2

    Fun small project.

  • @FeanorPhys
    @FeanorPhys 7 месяцев назад

    Thank you for this amazing explanation.

  • @valn1xd873
    @valn1xd873 11 месяцев назад

    you can skip most of it and just count the pixels and divide

    • @YounesLab
      @YounesLab  11 месяцев назад

      This is a solution indeed.
      Though by counting the pixels, you have to count all the pixels, this can often be computationally heavy, but by randomly selecting a fraction of a group (or pixels) you reduce dramatically the computational time and achieve a satisfying precision. This technique is a core in Path Tracing, Physics related phenomena and so on...

    • @valn1xd873
      @valn1xd873 11 месяцев назад

      you can use the gpu to do those simple operations

    • @bartx3709
      @bartx3709 11 месяцев назад

      ​​@@valn1xd873It's not about it. In this case it's just a circle but MC method can be great when what you're trying to estimate is some complicated integral of a more complicated function or area of some intricate shape.

    • @valn1xd873
      @valn1xd873 11 месяцев назад

      @@bartx3709 yeah, i understand, but i am an egineer so efficiency is the name of the game to me lol

    • @valn1xd873
      @valn1xd873 11 месяцев назад

      that reminds me of a time some math youtuber asked his subscribers to make some code thats faster than the code he wrote(that took hours to run) and people went crazy with it, doing some advanced code chemistry to squeeze every ms out of the code and got it to run in under a second