Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,23 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
|
||||
|
||||
procedure Test_Monte_Carlo is
|
||||
Dice : Generator;
|
||||
|
||||
function Pi (Throws : Positive) return Float is
|
||||
Inside : Natural := 0;
|
||||
begin
|
||||
for Throw in 1..Throws loop
|
||||
if Random (Dice) ** 2 + Random (Dice) ** 2 <= 1.0 then
|
||||
Inside := Inside + 1;
|
||||
end if;
|
||||
end loop;
|
||||
return 4.0 * Float (Inside) / Float (Throws);
|
||||
end Pi;
|
||||
begin
|
||||
Put_Line (" 10_000:" & Float'Image (Pi ( 10_000)));
|
||||
Put_Line (" 100_000:" & Float'Image (Pi ( 100_000)));
|
||||
Put_Line (" 1_000_000:" & Float'Image (Pi ( 1_000_000)));
|
||||
Put_Line (" 10_000_000:" & Float'Image (Pi ( 10_000_000)));
|
||||
Put_Line ("100_000_000:" & Float'Image (Pi (100_000_000)));
|
||||
end Test_Monte_Carlo;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
Pi: function [throws][
|
||||
inside: new 0.0
|
||||
inside: 0.0
|
||||
do.times: throws [
|
||||
if 1 > hypot random 0 1.0 random 0 1.0 -> inc 'inside
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
func mc n .
|
||||
fastfunc mc n .
|
||||
for i = 1 to n
|
||||
x = randomf
|
||||
y = randomf
|
||||
|
|
@ -7,7 +7,10 @@ func mc n .
|
|||
return 4 * hit / n
|
||||
.
|
||||
numfmt 0 4
|
||||
print mc 100
|
||||
print mc 1000
|
||||
print mc 10000
|
||||
print mc 100000
|
||||
print mc 1000000
|
||||
print mc 10000000
|
||||
print mc 100000000
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
function Get-Pi ($Iterations = 10000) {
|
||||
$InCircle = 0
|
||||
for ($i = 0; $i -lt $Iterations; $i++) {
|
||||
$x = Get-Random 1.0
|
||||
$y = Get-Random 1.0
|
||||
if ([Math]::Sqrt($x * $x + $y * $y) -le 1) {
|
||||
$InCircle++
|
||||
}
|
||||
}
|
||||
$Pi = [decimal] $InCircle / $Iterations * 4
|
||||
$RealPi = [decimal] "3.141592653589793238462643383280"
|
||||
$Diff = [Math]::Abs(($Pi - $RealPi) / $RealPi * 100)
|
||||
New-Object PSObject `
|
||||
| Add-Member -PassThru NoteProperty Iterations $Iterations `
|
||||
| Add-Member -PassThru NoteProperty Pi $Pi `
|
||||
| Add-Member -PassThru NoteProperty "% Difference" $Diff
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue