Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,26 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Numerics.Generic_Elementary_Functions;
|
||||
|
||||
procedure Arith_Geom_Mean is
|
||||
|
||||
type Num is digits 18; -- the largest value gnat/gcc allows
|
||||
package N_IO is new Ada.Text_IO.Float_IO(Num);
|
||||
package Math is new Ada.Numerics.Generic_Elementary_Functions(Num);
|
||||
|
||||
function AGM(A, G: Num) return Num is
|
||||
Old_G: Num;
|
||||
New_G: Num := G;
|
||||
New_A: Num := A;
|
||||
begin
|
||||
loop
|
||||
Old_G := New_G;
|
||||
New_G := Math.Sqrt(New_A*New_G);
|
||||
New_A := (Old_G + New_A) * 0.5;
|
||||
exit when (New_A - New_G) <= Num'Epsilon;
|
||||
-- Num'Epsilon denotes the relative error when performing arithmetic over Num
|
||||
end loop;
|
||||
return New_G;
|
||||
end AGM;
|
||||
|
||||
begin
|
||||
N_IO.Put(AGM(1.0, 1.0/Math.Sqrt(2.0)), Fore => 1, Aft => 17, Exp => 0);
|
||||
end Arith_Geom_Mean;
|
||||
|
|
@ -10,8 +10,4 @@ agm: function [a,g][
|
|||
return aOld
|
||||
]
|
||||
|
||||
print agm 1.0 1.0/sqrt 2.0</lang>
|
||||
|
||||
{{out}}
|
||||
|
||||
<pre>0.8472130847939792</pre>
|
||||
print agm 1.0 1.0/sqrt 2.0
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. ARITHMETIC-GEOMETRIC-MEAN-PROG.
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 AGM-VARS.
|
||||
05 A PIC 9V9(16).
|
||||
05 A-ZERO PIC 9V9(16).
|
||||
05 G PIC 9V9(16).
|
||||
05 DIFF PIC 9V9(16) VALUE 1.
|
||||
* Initialize DIFF with a non-zero value, otherwise AGM-PARAGRAPH
|
||||
* is never performed at all.
|
||||
PROCEDURE DIVISION.
|
||||
TEST-PARAGRAPH.
|
||||
MOVE 1 TO A.
|
||||
COMPUTE G = 1 / FUNCTION SQRT(2).
|
||||
* The program will run with the test values. If you would rather
|
||||
* calculate the AGM of numbers input at the console, comment out
|
||||
* TEST-PARAGRAPH and un-comment-out INPUT-A-AND-G-PARAGRAPH.
|
||||
* INPUT-A-AND-G-PARAGRAPH.
|
||||
* DISPLAY 'Enter two numbers.'
|
||||
* ACCEPT A.
|
||||
* ACCEPT G.
|
||||
CONTROL-PARAGRAPH.
|
||||
PERFORM AGM-PARAGRAPH UNTIL DIFF IS LESS THAN 0.000000000000001.
|
||||
DISPLAY A.
|
||||
STOP RUN.
|
||||
AGM-PARAGRAPH.
|
||||
MOVE A TO A-ZERO.
|
||||
COMPUTE A = (A-ZERO + G) / 2.
|
||||
MULTIPLY A-ZERO BY G GIVING G.
|
||||
COMPUTE G = FUNCTION SQRT(G).
|
||||
SUBTRACT A FROM G GIVING DIFF.
|
||||
COMPUTE DIFF = FUNCTION ABS(DIFF).
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
function agm ([Double]$a, [Double]$g) {
|
||||
[Double]$eps = 1E-15
|
||||
[Double]$a1 = [Double]$g1 = 0
|
||||
while([Math]::Abs($a - $g) -gt $eps) {
|
||||
$a1, $g1 = $a, $g
|
||||
$a = ($a1 + $g1)/2
|
||||
$g = [Math]::Sqrt($a1*$g1)
|
||||
}
|
||||
[pscustomobject]@{
|
||||
a = "$a"
|
||||
g = "$g"
|
||||
}
|
||||
}
|
||||
agm 1 (1/[Math]::Sqrt(2))
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
Function agm(a,g)
|
||||
Do Until a = tmp_a
|
||||
tmp_a = a
|
||||
a = (a + g)/2
|
||||
g = Sqr(tmp_a * g)
|
||||
Loop
|
||||
agm = a
|
||||
End Function
|
||||
|
||||
WScript.Echo agm(1,1/Sqr(2))
|
||||
Loading…
Add table
Add a link
Reference in a new issue