Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,119 +0,0 @@
with Ada.Text_IO;
with Ada.Numerics.Generic_Real_Arrays;
procedure Gaussian_Eliminations is
type Real is new Float;
package Real_Arrays is
new Ada.Numerics.Generic_Real_Arrays (Real);
use Real_Arrays;
function Gaussian_Elimination (A : in Real_Matrix;
B : in Real_Vector) return Real_Vector
is
procedure Swap_Row (A : in out Real_Matrix;
B : in out Real_Vector;
R_1, R_2 : in Integer)
is
Temp : Real;
begin
if R_1 = R_2 then return; end if;
-- Swal matrix row
for Col in A'Range (1) loop
Temp := A (R_1, Col);
A (R_1, Col) := A (R_2, Col);
A (R_2, Col) := Temp;
end loop;
-- Swap vector row
Temp := B (R_1);
B (R_1) := B (R_2);
B (R_2) := Temp;
end Swap_Row;
AC : Real_Matrix := A;
BC : Real_Vector := B;
X : Real_Vector (A'Range (1)) := BC;
Max, Tmp : Real;
Max_Row : Integer;
begin
if
A'Length (1) /= A'Length (2) or
A'Length (1) /= B'Length
then
raise Constraint_Error with "Dimensions do not match";
end if;
if
A'First (1) /= A'First (2) or
A'First (1) /= B'First
then
raise Constraint_Error with "First index must be same";
end if;
for Dia in Ac'Range (1) loop
Max_Row := Dia;
Max := Ac (Dia, Dia);
for Row in Dia + 1 .. Ac'Last (1) loop
Tmp := abs (Ac (Row, Dia));
if Tmp > Max then
Max_Row := Row;
Max := Tmp;
end if;
end loop;
Swap_Row (Ac, Bc, Dia, Max_Row);
for Row in Dia + 1 .. Ac'Last (1) loop
Tmp := Ac (Row, Dia) / Ac (Dia, Dia);
for Col in Dia + 1 .. Ac'Last (1) loop
Ac (Row, Col) := Ac (Row, Col) - Tmp * Ac (Dia, Col);
end loop;
Ac (Row, Dia) := 0.0;
Bc (Row) := Bc (Row) - Tmp * Bc (Dia);
end loop;
end loop;
for Row in reverse Ac'Range (1) loop
Tmp := Bc (Row);
for J in reverse Row + 1 .. Ac'Last (1) loop
Tmp := Tmp - X (J) * Ac (Row, J);
end loop;
X (Row) := Tmp / Ac (Row, Row);
end loop;
return X;
end Gaussian_Elimination;
procedure Put (V : in Real_Vector) is
use Ada.Text_IO;
package Real_IO is
new Ada.Text_IO.Float_IO (Real);
begin
Put ("[ ");
for E of V loop
Real_IO.Put (E, Exp => 0, Aft => 6);
Put (" ");
end loop;
Put (" ]");
New_Line;
end Put;
A : constant Real_Matrix :=
((1.00, 0.00, 0.00, 0.00, 0.00, 0.00),
(1.00, 0.63, 0.39, 0.25, 0.16, 0.10),
(1.00, 1.26, 1.58, 1.98, 2.49, 3.13),
(1.00, 1.88, 3.55, 6.70, 12.62, 23.80),
(1.00, 2.51, 6.32, 15.88, 39.90, 100.28),
(1.00, 3.14, 9.87, 31.01, 97.41, 306.02));
B : constant Real_Vector :=
( -0.01, 0.61, 0.91, 0.99, 0.60, 0.02 );
X : constant Real_Vector := Gaussian_Elimination (A, B);
begin
Put (X);
end Gaussian_Eliminations;

View file

@ -1,53 +0,0 @@
function gauss($a,$b) {
$n = $a.count
for ($k = 0; $k -lt $n; $k++) {
$lmax, $max = $k, [Math]::Abs($a[$k][$k])
for ($l = $k+1; $l -lt $n; $l++) {
$tmp = [Math]::Abs($a[$l][$k])
if($max -lt $tmp) {
$max, $lmax = $tmp, $l
}
}
if ($k -ne $lmax) {
$a[$k], $a[$lmax] = $a[$lmax], $a[$k]
$b[$k], $b[$lmax] = $b[$lmax], $b[$k]
}
$akk = $a[$k][$k]
for ($i = $k+1; $i -lt $n; $i++){
$aik = $a[$i][$k]
for ($j = $k; $j -lt $n; $j++) {
$a[$i][$j] = $a[$i][$j]*$akk - $a[$k][$j]*$aik
}
$b[$i] = $b[$i]*$akk - $b[$k]*$aik
}
}
for ($i = $n-1; $i -ge 0; $i--) {
for ($j = $i+1; $j -lt $n; $j++) {
$b[$i] -= $b[$j]*$a[$i][$j]
}
$b[$i] = $b[$i]/$a[$i][$i]
}
$b
}
function show($a) {
if($a) {
0..($a.Count - 1) | foreach{ if($a[$_]){"$($a[$_][0..($a[$_].count -1)])"}else{""} }
}
}
$a =(
@(1.00, 0.00, 0.00, 0.00, 0.00, 0.00),
@(1.00, 0.63, 0.39, 0.25, 0.16, 0.10),
@(1.00, 1.26, 1.58, 1.98, 2.49, 3.13),
@(1.00, 1.88, 3.55, 6.70, 12.62, 23.80),
@(1.00, 2.51, 6.32, 15.88, 39.90, 100.28),
@(1.00, 3.14, 9.87, 31.01, 97.41, 306.02)
)
"a ="
show $a
""
$b = @(-0.01, 0.61, 0.91, 0.99, 0.60, 0.02)
"b ="
$b
""
"x ="
gauss $a $b

View file

@ -1,51 +0,0 @@
function gauss-jordan($a,$b) {
$n = $a.count
for ($k = 0; $k -lt $n; $k++) {
$lmax, $max = $k, [Math]::Abs($a[$k][$k])
for ($l = $k+1; $l -lt $n; $l++) {
$tmp = [Math]::Abs($a[$l][$k])
if($max -lt $tmp) {
$max, $lmax = $tmp, $l
}
}
if ($k -ne $lmax) {
$a[$k], $a[$lmax] = $a[$lmax], $a[$k]
$b[$k], $b[$lmax] = $b[$lmax], $b[$k]
}
$akk = $a[$k][$k]
for ($j = $k; $j -lt $n; $j++) {$a[$k][$j] /= $akk}
$b[$k] /= $akk
for ($i = 0; $i -lt $n; $i++){
if ($i -ne $k) {
$aik = $a[$i][$k]
for ($j = $k; $j -lt $n; $j++) {
$a[$i][$j] = $a[$i][$j] - $a[$k][$j]*$aik
}
$b[$i] = $b[$i] - $b[$k]*$aik
}
}
}
$b
}
function show($a) {
if($a) {
0..($a.Count - 1) | foreach{ if($a[$_]){"$($a[$_][0..($a[$_].count -1)])"}else{""} }
}
}
$a =(
@(1.00, 0.00, 0.00, 0.00, 0.00, 0.00),
@(1.00, 0.63, 0.39, 0.25, 0.16, 0.10),
@(1.00, 1.26, 1.58, 1.98, 2.49, 3.13),
@(1.00, 1.88, 3.55, 6.70, 12.62, 23.80),
@(1.00, 2.51, 6.32, 15.88, 39.90, 100.28),
@(1.00, 3.14, 9.87, 31.01, 97.41, 306.02)
)
"a ="
show $a
""
$b = @(-0.01, 0.61, 0.91, 0.99, 0.60, 0.02)
"b ="
$b
""
"x ="
gauss-jordan $a $b

View file

@ -1,46 +0,0 @@
' Gaussian elimination - VBScript
const n=6
dim a(6,6),b(6),x(6),ab
ab=array( 1 , 0 , 0 , 0 , 0 , 0 , -0.01, _
1 , 0.63, 0.39, 0.25, 0.16, 0.10, 0.61, _
1 , 1.26, 1.58, 1.98, 2.49, 3.13, 0.91, _
1 , 1.88, 3.55, 6.70, 12.62, 23.80, 0.99, _
1 , 2.51, 6.32, 15.88, 39.90, 100.28, 0.60, _
1 , 3.14, 9.87, 31.01, 97.41, 306.02, 0.02)
k=-1
for i=1 to n
buf=""
for j=1 to n+1
k=k+1
if j<=n then
a(i,j)=ab(k)
else
b(i)=ab(k)
end if
buf=buf&right(space(8)&formatnumber(ab(k),2),8)&" "
next
wscript.echo buf
next
for j=1 to n
for i=j+1 to n
w=a(j,j)/a(i,j)
for k=j+1 to n
a(i,k)=a(j,k)-w*a(i,k)
next
b(i)=b(j)-w*b(i)
next
next
x(n)=b(n)/a(n,n)
for j=n-1 to 1 step -1
w=0
for i=j+1 to n
w=w+a(j,i)*x(i)
next
x(j)=(b(j)-w)/a(j,j)
next
wscript.echo "solution"
buf=""
for i=1 to n
buf=buf&right(space(8)&formatnumber(x(i),2),8)&vbcrlf
next
wscript.echo buf