<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Commentaires sur : Mathematical digression : Buffon&#039;s needle</title>
	<atom:link href="http://blog.neteril.org/2009/05/18/mathematical-digression-buffons-needle/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.neteril.org/2009/05/18/mathematical-digression-buffons-needle/</link>
	<description>Random thoughts of Jérémie Laval</description>
	<lastBuildDate>Mon, 25 Jul 2011 10:32:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Par : Raphael Javaux</title>
		<link>http://blog.neteril.org/2009/05/18/mathematical-digression-buffons-needle/comment-page-1/#comment-164</link>
		<dc:creator>Raphael Javaux</dc:creator>
		<pubDate>Thu, 28 May 2009 18:02:43 +0000</pubDate>
		<guid isPermaLink="false">http://garuma.wordpress.com/?p=503#comment-164</guid>
		<description>Amusant, il y a quelques semaines, au cours de math, nous avons vu les intégrales (ouai bon je suis toujours en secondaire :P) et j&#039;ai trouvé un moyen très rapide d&#039;avoir une approxymation de PI (sans avoir un accès aux fonctions trigonometriques). Testé sur une Casio en CasioBasic \o/.

Les intégralles permettent d&#039;obtenir l&#039;aire d&#039;une fonction. Et PI est le rapport entre la circonférence du cercle et son rayon, mais nous savons aussi que PI*R² = Aire.
Il suffit donc de prendre la formule du cercle (en réalité le demi-cercle pusique une fonction ne connais que une image pour un X): Y = SQRT(R-X²).
Et d&#039;y calculer son aire entre 0 et 1 pour un demi-cercle de 1 de rayon et de la multiplier par 4 (puisque 0 et 1 ne sont que un quart de cercle), de là nous aurons directement PI (Si R = 1 =&gt; PI*R² = PI, PI est donc l&#039;aire du cercle). Les intégrales nous permettent de calculer cette aire.

On peu avoir une estimation d&#039;une intégralle en additionant des échantillon d&#039;aire de la fonction en &quot;testant&quot; la fonction sur plusieurs valeurs de X. Plus nous testons d&#039;échantillons, plus la valeur sera précise : http://files.getwebb.org/index.php?mode=view&amp;id=cre66i0p

Et le code: http://pastebin.com/f447dec0c

On peut voir que l&#039;estimation est beaucoup plus proche de PI, on peut atteindre le même degré de précision avec seulement 100 itérations :-). Mais ca reste assez lourd à cause de SQRT() (même si 100 itération doivent quand même s&#039;exécuter plus vite que 1000000).

Il existe aussi une fonction beaucoup plus simple mais il ne s&#039;agit pas d&#039;une approximation et le temps de calcul de chaque décimale et relativement exponentielle:
PI = 1 / 1 - 1 / 2 + 1 / 3 ...((-1 * (n+1)%2) * 1) / n</description>
		<content:encoded><![CDATA[<p>Amusant, il y a quelques semaines, au cours de math, nous avons vu les intégrales (ouai bon je suis toujours en secondaire <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ) et j&#8217;ai trouvé un moyen très rapide d&#8217;avoir une approxymation de PI (sans avoir un accès aux fonctions trigonometriques). Testé sur une Casio en CasioBasic \o/.</p>
<p>Les intégralles permettent d&#8217;obtenir l&#8217;aire d&#8217;une fonction. Et PI est le rapport entre la circonférence du cercle et son rayon, mais nous savons aussi que PI*R² = Aire.<br />
Il suffit donc de prendre la formule du cercle (en réalité le demi-cercle pusique une fonction ne connais que une image pour un X): Y = SQRT(R-X²).<br />
Et d&#8217;y calculer son aire entre 0 et 1 pour un demi-cercle de 1 de rayon et de la multiplier par 4 (puisque 0 et 1 ne sont que un quart de cercle), de là nous aurons directement PI (Si R = 1 =&gt; PI*R² = PI, PI est donc l&#8217;aire du cercle). Les intégrales nous permettent de calculer cette aire.</p>
<p>On peu avoir une estimation d&#8217;une intégralle en additionant des échantillon d&#8217;aire de la fonction en &laquo;&nbsp;testant&nbsp;&raquo; la fonction sur plusieurs valeurs de X. Plus nous testons d&#8217;échantillons, plus la valeur sera précise : <a href="http://files.getwebb.org/index.php?mode=view&#038;id=cre66i0p" rel="nofollow">http://files.getwebb.org/index.php?mode=view&#038;id=cre66i0p</a></p>
<p>Et le code: <a href="http://pastebin.com/f447dec0c" rel="nofollow">http://pastebin.com/f447dec0c</a></p>
<p>On peut voir que l&#8217;estimation est beaucoup plus proche de PI, on peut atteindre le même degré de précision avec seulement 100 itérations <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . Mais ca reste assez lourd à cause de SQRT() (même si 100 itération doivent quand même s&#8217;exécuter plus vite que 1000000).</p>
<p>Il existe aussi une fonction beaucoup plus simple mais il ne s&#8217;agit pas d&#8217;une approximation et le temps de calcul de chaque décimale et relativement exponentielle:<br />
PI = 1 / 1 &#8211; 1 / 2 + 1 / 3 &#8230;((-1 * (n+1)%2) * 1) / n</p>
]]></content:encoded>
	</item>
	<item>
		<title>Par : garuma</title>
		<link>http://blog.neteril.org/2009/05/18/mathematical-digression-buffons-needle/comment-page-1/#comment-163</link>
		<dc:creator>garuma</dc:creator>
		<pubDate>Tue, 19 May 2009 16:57:22 +0000</pubDate>
		<guid isPermaLink="false">http://garuma.wordpress.com/?p=503#comment-163</guid>
		<description>@gliss:
It&#039;s yet another one of those &quot;repeat it a lot to see where it converges&quot; :-) .

@shamaz:
Yeah, I coded it just for fun (and because I don&#039;t have the luxury to throw needles on my parquet all day long :-) ).

@Barry:
Nice one.

I don&#039;t think there is really a &quot;hidden&quot; pi in the method since you can express your sin function without any kind of pi (via series for instance). But, agreed, it&#039;s disputable :-) .</description>
		<content:encoded><![CDATA[<p>@gliss:<br />
It&#8217;s yet another one of those &laquo;&nbsp;repeat it a lot to see where it converges&nbsp;&raquo; <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  .</p>
<p>@shamaz:<br />
Yeah, I coded it just for fun (and because I don&#8217;t have the luxury to throw needles on my parquet all day long <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).</p>
<p>@Barry:<br />
Nice one.</p>
<p>I don&#8217;t think there is really a &laquo;&nbsp;hidden&nbsp;&raquo; pi in the method since you can express your sin function without any kind of pi (via series for instance). But, agreed, it&#8217;s disputable <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  .</p>
]]></content:encoded>
	</item>
	<item>
		<title>Par : Barry Kelly</title>
		<link>http://blog.neteril.org/2009/05/18/mathematical-digression-buffons-needle/comment-page-1/#comment-162</link>
		<dc:creator>Barry Kelly</dc:creator>
		<pubDate>Tue, 19 May 2009 13:42:42 +0000</pubDate>
		<guid isPermaLink="false">http://garuma.wordpress.com/?p=503#comment-162</guid>
		<description>Of course, if you have access to a Sin function, you already have an easier way to get to Pi - just find out what x makes Sin(x) = 1, and double it. And of course, your sample code is using PI directly, albeit to range-limit an angle selection.

A more interesting method, in a didactic sense, is to estimate the proportion of the area of a circle to the area of its smallest enclosing square. The area of the circle is pi*r*r, while the area of the square is 4*r*r. Dividing one by the other, as estimated by needle drops (x,y) where both x and y are in the domain -r..r and tested with circle equation of x*x+y*y=r*r (&gt;r*r =&gt; outside circle), and you have a way of probabilistically estimating pi without any hidden pi in the methodology.

Here&#039;s some sample code:

using System;

class App
{
    const int Iter = 1000000;

    static void Main()
    {
        Random r = new Random();
        double radius = 0.5;
        double radiusSquared = radius * radius;
        int hitCount = 0;

        for (int i = 0; i &lt; Iter; ++i)
        {
            double x = r.NextDouble() * radius * 2 - radius;
            double y = r.NextDouble() * radius * 2 - radius;
            if (x * x + y * y &lt;= radiusSquared)
                ++hitCount;
        }

        // area of circle / area of square
        // = pi * r * r / 4 * r * r
        // = pi / 4
        double proportion = hitCount / (double) Iter;
        Console.WriteLine(&quot;Pi estimated at {0}&quot;, proportion * 4);
    }
}</description>
		<content:encoded><![CDATA[<p>Of course, if you have access to a Sin function, you already have an easier way to get to Pi &#8211; just find out what x makes Sin(x) = 1, and double it. And of course, your sample code is using PI directly, albeit to range-limit an angle selection.</p>
<p>A more interesting method, in a didactic sense, is to estimate the proportion of the area of a circle to the area of its smallest enclosing square. The area of the circle is pi*r*r, while the area of the square is 4*r*r. Dividing one by the other, as estimated by needle drops (x,y) where both x and y are in the domain -r..r and tested with circle equation of x*x+y*y=r*r (&gt;r*r =&gt; outside circle), and you have a way of probabilistically estimating pi without any hidden pi in the methodology.</p>
<p>Here&#8217;s some sample code:</p>
<p>using System;</p>
<p>class App<br />
{<br />
    const int Iter = 1000000;</p>
<p>    static void Main()<br />
    {<br />
        Random r = new Random();<br />
        double radius = 0.5;<br />
        double radiusSquared = radius * radius;<br />
        int hitCount = 0;</p>
<p>        for (int i = 0; i &lt; Iter; ++i)<br />
        {<br />
            double x = r.NextDouble() * radius * 2 &#8211; radius;<br />
            double y = r.NextDouble() * radius * 2 &#8211; radius;<br />
            if (x * x + y * y &lt;= radiusSquared)<br />
                ++hitCount;<br />
        }</p>
<p>        // area of circle / area of square<br />
        // = pi * r * r / 4 * r * r<br />
        // = pi / 4<br />
        double proportion = hitCount / (double) Iter;<br />
        Console.WriteLine(&laquo;&nbsp;Pi estimated at {0}&nbsp;&raquo;, proportion * 4);<br />
    }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>Par : shamaz</title>
		<link>http://blog.neteril.org/2009/05/18/mathematical-digression-buffons-needle/comment-page-1/#comment-161</link>
		<dc:creator>shamaz</dc:creator>
		<pubDate>Tue, 19 May 2009 13:32:01 +0000</pubDate>
		<guid isPermaLink="false">http://garuma.wordpress.com/?p=503#comment-161</guid>
		<description>using the sine function to approximate Pi, ss a chicken egg problem for me :)</description>
		<content:encoded><![CDATA[<p>using the sine function to approximate Pi, ss a chicken egg problem for me <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Par : Gliss</title>
		<link>http://blog.neteril.org/2009/05/18/mathematical-digression-buffons-needle/comment-page-1/#comment-160</link>
		<dc:creator>Gliss</dc:creator>
		<pubDate>Tue, 19 May 2009 07:56:11 +0000</pubDate>
		<guid isPermaLink="false">http://garuma.wordpress.com/?p=503#comment-160</guid>
		<description>This method is also referred to as the Monte Carlo method, although it&#039;s just one application among others in the Monte Carlo algorithm class.</description>
		<content:encoded><![CDATA[<p>This method is also referred to as the Monte Carlo method, although it&#8217;s just one application among others in the Monte Carlo algorithm class.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

