Pi_30K.gif(500 × 500 billedpunkter, filstørrelse: 476 KB, MIME-type: image/gif, gentaget, 10 rammer, 2,0 s)


Denne fil er fra Wikimedia Commons

Beskrivelse

 
GIF Rastergrafik blev lavet med Matplotlib.
Beskrivelse
English: As points are randomly scattered inside the unit square, some fall within the unit circle. The fraction of points inside the circle over all points approaches pi/4 as the number of points goes toward infinity. This animation represents this method of computing pi out to 30,000 iterations.
Kilde Eget arbejde
Forfatter nicoguaro
Kildekode
InfoField

Python code

from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.animation as animation
from matplotlib import rcParams

# In Windows the next line should provide the full path to convert.exe
# since convert is a Windows command
#rcParams['animation.convert_path'] = "C:\Program Files\ImageMagick-6.9.3\convert.exe"
rcParams['mathtext.fontset'] = 'cm'
rcParams['font.size'] = 14


red = "#e41a1c"
blue = "#377eb8"
gray = "#eeeeee"


def update(n):
    ax.cla()
    pts = np.random.uniform(low=0, high=1, size=(2, n))
    circ = pts[:, pts[0, :]**2 + pts[1, :]**2 <= 1]
    out_circ = pts[:, pts[0, :]**2 + pts[1, :]**2 > 1]
    pi_approx = 4*circ.shape[1]/n
    circle = mpatches.Wedge((0, 0), 1, 0, 90,  color=gray)
    ax.add_artist(circle)
    plt.plot(circ[0, :], circ[1, :], marker='.', markersize=1,
             linewidth=0, color=red)
    plt.plot(out_circ[0, :], out_circ[1, :], marker='.',markersize=1,
             linewidth=0, color=blue)
    plt.title(r"$n = {}, \pi \approx {:.4f}$".format(n, pi_approx))
    plt.axis("square")
    plt.xlim(0, 1)
    plt.ylim(0, 1)


nvec = np.round(np.logspace(2, 5, 10))
nvec = [3000, 4000, 5000, 6500, 8500, 10000, 15000, 18000, 24000, 30000]
fig = plt.figure(figsize=(5, 5))
ax = fig.add_subplot(111)
ani = animation.FuncAnimation(fig, update, frames=nvec, blit=False)
ani.save("monte_carlo_pi.gif", writer='imagemagick',
         savefig_kwargs={'delay': 6})

Licensering

Jeg, dette værks ophavsretsindehaver, publicerer hermed værket under den følgende licens:
w:da:Creative Commons
kreditering
Denne fil er licenseret under Creative Commons Navngivelse 3.0 Unported-licensen.
Du må frit:
  • at dele – at kopiere, distribuere og overføre værket
  • at remixe – at tilpasse værket
Under følgende vilkår:
  • kreditering – Du skal give passende kreditering, angive et link til licensen, og oplyse om der er foretaget ændringer. Du må gøre det på enhver fornuftig måde, men ikke på en måde der antyder at licensgiveren godkender dig eller din anvendelse.

Captions

Tilføj en kort forklaring på en enkelt linje om hvad filen viser

Elementer som er med i denne fil

afbilder

image/gif

Filhistorik

Klik på en dato/tid for at se filen som den så ud på det tidspunkt.

Dato/tidMiniaturebilledeDimensionerBrugerKommentar
nuværende16. feb. 2017, 18:00Miniature af versionen fra 16. feb. 2017, 18:00500 × 500 (476 KB)NicoguaroMake the plot square and increase gif delay.
16. feb. 2017, 17:38Miniature af versionen fra 16. feb. 2017, 17:38640 × 480 (476 KB)NicoguaroBigger text in the axes, and colors from ColorBrewer. Code in Python.
7. nov. 2011, 20:29Miniature af versionen fra 7. nov. 2011, 20:29500 × 500 (373 KB)RayhemSlowed animation to avoid looking like a blinky page element, improved resolution, added counter for number of points, shaded points inside/outside the circle. ==Mathematica 7.0 Source== <pre> tinyColor[color_, point_] := {PointSize[Small], color, Point[
15. mar. 2011, 01:12Miniature af versionen fra 15. mar. 2011, 01:12360 × 369 (363 KB)CaitlinJo{{Information |Description ={{en|1=As points are randomly scattered inside the unit square, some fall within the unit circle. The fraction of points inside the circle over all points approaches pi as the number of points goes toward infinity. This ani

Den følgende side bruger denne fil:

Global filanvendelse

Følgende andre wikier anvender denne fil: