Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,10 +0,0 @@
|
|||
generic
|
||||
type Scalar is digits <>;
|
||||
with function F (X : Scalar) return Scalar;
|
||||
package Integrate is
|
||||
function Left_Rectangular (A, B : Scalar; N : Positive) return Scalar;
|
||||
function Right_Rectangular (A, B : Scalar; N : Positive) return Scalar;
|
||||
function Midpoint_Rectangular (A, B : Scalar; N : Positive) return Scalar;
|
||||
function Trapezium (A, B : Scalar; N : Positive) return Scalar;
|
||||
function Simpsons (A, B : Scalar; N : Positive) return Scalar;
|
||||
end Integrate;
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
package body Integrate is
|
||||
function Left_Rectangular (A, B : Scalar; N : Positive) return Scalar is
|
||||
H : constant Scalar := (B - A) / Scalar (N);
|
||||
Sum : Scalar := 0.0;
|
||||
X : Scalar;
|
||||
begin
|
||||
for I in 0 .. N - 1 loop
|
||||
X := A + Scalar (I) * H;
|
||||
Sum := Sum + H * F (X);
|
||||
end loop;
|
||||
return Sum;
|
||||
end Left_Rectangular;
|
||||
|
||||
function Right_Rectangular (A, B : Scalar; N : Positive) return Scalar is
|
||||
H : constant Scalar := (B - A) / Scalar (N);
|
||||
Sum : Scalar := 0.0;
|
||||
X : Scalar;
|
||||
begin
|
||||
for I in 1 .. N loop
|
||||
X := A + Scalar (I) * H;
|
||||
Sum := Sum + H * F (X);
|
||||
end loop;
|
||||
return Sum;
|
||||
end Right_Rectangular;
|
||||
|
||||
function Midpoint_Rectangular (A, B : Scalar; N : Positive) return Scalar is
|
||||
H : constant Scalar := (B - A) / Scalar (N);
|
||||
Sum : Scalar := 0.0;
|
||||
X : Scalar;
|
||||
begin
|
||||
for I in 1 .. N loop
|
||||
X := A + Scalar (I) * H - 0.5 * H;
|
||||
Sum := Sum + H * F (X);
|
||||
end loop;
|
||||
return Sum;
|
||||
end Midpoint_Rectangular;
|
||||
|
||||
function Trapezium (A, B : Scalar; N : Positive) return Scalar is
|
||||
H : constant Scalar := (B - A) / Scalar (N);
|
||||
Sum : Scalar := F(A) + F(B);
|
||||
X : Scalar := 1.0;
|
||||
begin
|
||||
while X <= Scalar (N) - 1.0 loop
|
||||
Sum := Sum + 2.0 * F (A + X * (B - A) / Scalar (N));
|
||||
X := X + 1.0;
|
||||
end loop;
|
||||
return (B - A) / (2.0 * Scalar (N)) * Sum;
|
||||
end Trapezium;
|
||||
|
||||
function Simpsons (A, B : Scalar; N : Positive) return Scalar is
|
||||
H : constant Scalar := (B - A) / Scalar (N);
|
||||
Sum_U : Scalar := 0.0;
|
||||
Sum_E : Scalar := 0.0;
|
||||
begin
|
||||
for I in 1 .. N - 1 loop
|
||||
if I mod 2 /= 0 then
|
||||
Sum_U := Sum_U + F (A + H * Scalar (I));
|
||||
else
|
||||
Sum_E := Sum_E + F (A + H * Scalar (I));
|
||||
end if;
|
||||
end loop;
|
||||
return (H / 3.0) * (F (A) + F (B) + 4.0 * Sum_U + 2.0 * Sum_E);
|
||||
end Simpsons;
|
||||
end Integrate;
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
with Ada.Text_IO, Ada.Integer_Text_IO;
|
||||
with Integrate;
|
||||
|
||||
procedure Numerical_Integration is
|
||||
type Scalar is digits 18;
|
||||
package Scalar_Text_IO is new Ada.Text_IO.Float_IO (Scalar);
|
||||
|
||||
generic
|
||||
with function F (X : Scalar) return Scalar;
|
||||
Name : String;
|
||||
From, To : Scalar;
|
||||
Steps : Positive;
|
||||
procedure Test;
|
||||
|
||||
procedure Test is
|
||||
package Integrate_Scalar_F is new Integrate (Scalar, F);
|
||||
use Ada.Text_IO, Ada.Integer_Text_IO, Integrate_Scalar_F, Scalar_Text_IO;
|
||||
begin
|
||||
Put (Name & " integrated from ");
|
||||
Put (From);
|
||||
Put (" to ");
|
||||
Put (To);
|
||||
Put (" in ");
|
||||
Put (Steps);
|
||||
Put_Line (" steps:");
|
||||
|
||||
Put ("Rectangular (left): ");
|
||||
Put (Left_Rectangular (From, To, Steps));
|
||||
New_Line;
|
||||
|
||||
Put ("Rectangular (right): ");
|
||||
Put (Right_Rectangular (From, To, Steps));
|
||||
New_Line;
|
||||
|
||||
Put ("Rectangular (midpoint): ");
|
||||
Put (Midpoint_Rectangular (From, To, Steps));
|
||||
New_Line;
|
||||
|
||||
Put ("Trapezium: ");
|
||||
Put (Trapezium (From, To, Steps));
|
||||
New_Line;
|
||||
|
||||
Put ("Simpson's: ");
|
||||
Put (Simpsons (From, To, Steps));
|
||||
New_Line;
|
||||
|
||||
New_Line;
|
||||
end Test;
|
||||
begin
|
||||
Ada.Integer_Text_IO.Default_Width := 0;
|
||||
Scalar_Text_IO.Default_Fore := 0;
|
||||
Scalar_Text_IO.Default_Exp := 0;
|
||||
|
||||
Cubed:
|
||||
declare
|
||||
function F (X : Scalar) return Scalar is
|
||||
begin
|
||||
return X ** 3;
|
||||
end F;
|
||||
procedure Run is new Test (F => F,
|
||||
Name => "x^3",
|
||||
From => 0.0,
|
||||
To => 1.0,
|
||||
Steps => 100);
|
||||
begin
|
||||
Run;
|
||||
end Cubed;
|
||||
|
||||
One_Over_X:
|
||||
declare
|
||||
function F (X : Scalar) return Scalar is
|
||||
begin
|
||||
return 1.0 / X;
|
||||
end F;
|
||||
procedure Run is new Test (F => F,
|
||||
Name => "1/x",
|
||||
From => 1.0,
|
||||
To => 100.0,
|
||||
Steps => 1_000);
|
||||
begin
|
||||
Run;
|
||||
end One_Over_X;
|
||||
|
||||
X:
|
||||
declare
|
||||
function F (X : Scalar) return Scalar is
|
||||
begin
|
||||
return X;
|
||||
end F;
|
||||
procedure Run_1 is new Test (F => F,
|
||||
Name => "x",
|
||||
From => 0.0,
|
||||
To => 5_000.0,
|
||||
Steps => 5_000_000);
|
||||
procedure Run_2 is new Test (F => F,
|
||||
Name => "x",
|
||||
From => 0.0,
|
||||
To => 6_000.0,
|
||||
Steps => 6_000_000);
|
||||
begin
|
||||
Run_1;
|
||||
Run_2;
|
||||
end X;
|
||||
end Numerical_Integration;
|
||||
Loading…
Add table
Add a link
Reference in a new issue